2

我正在使用 Elastic Search 为名为 people 的索引实现自动建议字段:

该字段的映射如下person_name_suggest-

person_name_suggest: {
  type: "completion",
  analyzer: "simple",
  payloads: true,
  preserve_separators: true,
  preserve_position_increments: true,
  max_input_length: 50,
  context: {
    office_scope: {
     type: "category",
     path: "office_scope",
     default: [
       "0"
     ]
   }
  }
},

我需要弹性搜索的请求如下:

{ 
 "suggest":{
  "suggestions":{
    "text":"M","
    completion":{
     "field":"person_name_suggest",
     "context":890,
     "size":10
    }
   }
 }
}

我收到以下错误 - "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[OsbgjmewT569a-7ZoNCMtg][people_2016_10_29][0]: SearchParseException[[people_2016_10_29][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"suggest":{"suggestions":{"text":"M","completion":{"field":"person_name_suggest","context":890,"size":10}}}}]]]; nested: ElasticsearchIllegalArgumentException[suggester [completion] requires context to be setup]; }

据我所知,我已经正确设置了完成建议器。

有人能指出我正确的方向吗?

正在使用的 ElasticSearch 版本是1.6

4

1 回答 1

1

查询中有语法错误。您必须指定上下文的名称

尝试这个

{ 
 "suggest":{
  "suggestions":{
    "text":"M","
    completion":{
     "field":"person_name_suggest",
     "context":{"office_scope":890},
     "size":10
    }
   }
 }
}
于 2016-10-29T13:00:32.110 回答