Elasticseach完成建议者返回建议
问题描述:
当前堆栈涉及的node.js v0.12.7与elasticsearch-JS> = 1.1.0与Elasticsearch 1.7 API运行。Elasticseach完成建议者返回建议
我当前elasticsearch设置被映射到具有索引1与2种类型:
elasticsearch.client.indices.create({
index: 'randomindex',
body: {
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
},
"my_english": {
"type": "english",
"stopwords": "_english_"
}
}
}
},
'mappings': {
'countries': {
'properties': {
'country': {
'type': 'string',
'fields': {
"autocomplete": { "type": "string", "index_analyzer": "autocomplete", "search_analyzer": "my_english" }
}
},
"suggest_countries": {
"type": "completion",
"index_analyzer": "simple",
"search_analyzer": "simple",
"payloads": true
}
}
},
'some_other_type': {
'properties': {
"field_1": {
"type": "date"
},
"field_2": {
"type": "string"
},
"suggest_some_other_field": {
"type": "completion",
"index_analyzer": "simple",
"search_analyzer": "simple",
"payloads": false
}
}
}
}
}
});
我已经然后填充有相关的“输入”,“输出”和“有效载荷”字段都建议字段。
我想指定特定的索引类型从返回的建议,但我这样做时,它抛出的错误:
elasticsearch.clients.suggest({
index: "randomindex",
type: "countries",
body: {
"suggest": {
text: query,
completion: {
"field": "suggest_countries"
}
}
}
});
有什么办法我可以指定/指向特定类型的。建议方法?
答
你需要让你的呼叫而不type
参数
elasticsearch.clients.suggest({
index: "randomindex",
body: {
"suggest": {
text: query,
completion: {
"field": "suggest_countries"
}
}
}
});
看到官方文档的client.suggest()
call,没有可用的type
参数。
+0
这有什么好运气? – Val
请分享错误ES扔。 – Val
当我在节点上运行它时没有错误。它只是在响应对象中返回一个空的选项数组。然而,当我尝试通过谷歌浏览器的Sense扩展等客户端访问'/ randomindex/countries/_suggest'端点时,我传递了类似'{“suggest_countries”:{“text”:“a”,“completion”:{ “field”:“suggest_countries”}}}'它会抛出一个错误,如'MapperParsingException [解析失败];嵌套:ElasticsearchIllegalArgumentException [未知字段名称[文本],必须是[输出,上下文,输入,重量,有效载荷]];'中的一个。 –
我可以确保我已经在'autocomplete_countries'类型中正确填充'suggest_countries'字段,因为我已经在端点'/ randomindex/countries/_search'上检查了Sense,并且一切似乎都在那里。 –