ElasticsearchIllegalArgumentException

时间:2016-08-18 06:49:56

标签: elasticsearch elasticsearch-1.6.0

我的代码是

curl -XGET 'http://localhost:9200/web/_suggest?pretty' -d '
{ "brand-suggest": {"completion": {"field": "nameSuggest","size":   "5","context": { "private": "false" }}, "text": "sampl"}}'

尝试使用elasticsearch建议查询时出错。

"index" : "webpage",
      "shard" : 4,
      "status" : 500,
      "reason" : "BroadcastShardOperationFailedException[[tellofy][4] ];  nested: ElasticsearchException[failed to execute suggest]; nested: ElasticsearchIllegalArgumentException[suggester [completion] doesn't expect any context]; "
    }

上述错误的原因是什么?我无法找到该错误的原因。

1 个答案:

答案 0 :(得分:1)

nameSuggest有一个completion类型但没有context,因此您的建议查询不允许指定context

查看normal completion fieldscompletion fields with context

之间的区别

如果您希望运行以下查询

curl -XGET 'http://localhost:9200/web/_suggest?pretty' -d '{
  "brand-suggest": {
    "completion": {
      "field": "nameSuggest",
      "size": "5",
      "context": {
        "private": "false"
      }
    },
    "text": "sampl"
  }
}'

您需要将nameSuggest字段的映射更改为此,即添加上下文配置部分:

{
  "type": "completion",
  "analyzer": "simple",
  "search_analyzer": "simple",
  "context": {
    "private": {
      "type": "category",
      "path": "private"
    }
  }
}