我按照https://www.elastic.co/guide/en/elasticsearch/reference/current/suggester-context.html#suggester-context中的教程构建了索引。
PUT qs
{
"mappings": {
"questions" : {
"properties" : {
"suggest" : {
"type" : "completion",
"contexts": [
{
"name": "domain",
"type": "category",
"path": "domain"
}
]
}
}
}
}
}
对于每个问题,我都有
PUT qs/questions/1
{
"suggest": {
"input": ["a", "b", "c", "d"],
"contexts": {
"domain": ["domain1"]
},
"weight" : 2
}
}
最后,当我搜索时,我会使用
POST qs/_search?pretty
{
"suggest": {
"question-suggest" : {
"prefix" : "实名",
"completion" : {
"field" : "suggest",
"size": 100,
"contexts": {
"domain": [
{ "context" : "小金库", "boost" : 1},
{ "context" : "白条闪付", "boost": 4}
]
}
}
}
}
}
我想知道如何在Java中实现它?我已经尝试过
SearchResponse response = client.prepareSearch(esIndexName)
.setQuery(QueryBuilders.wrapperQuery(queryString))
.setTimeout(TimeValue.timeValueMillis(this.requestTimeout))
.setExplain(false)
.setSize(responseSize)
.execute()
.actionGet();
但这给了我一个例外
ParsingException [没有为[建议]注册的[查询]]
非常感谢您的帮助!