我的代码是
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]; "
}
上述错误的原因是什么?我无法找到该错误的原因。
答案 0 :(得分:1)
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"
}
}
}