我的代码是
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]; "
}
出现上述错误的原因是什么。我找不到该错误的原因。
最佳答案
nameSuggest
具有completion
类型,但没有context
,因此不允许您的建议查询指定context
看看normal completion
fields和 completion
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"
}
}
}
关于elasticsearch - ElasticsearchIllegalArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39011617/