当前堆栈涉及使用 Elasticsearch 1.7 API elasticsearch-js> = 1.1.0 运行的 node.js v0.12.7 。
我当前的弹性搜索设置被映射为具有2种类型的1个索引:
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"
}
}
}
});
有没有办法在.suggest方法中指定/引用特定类型?
答案 0 :(得分:0)
您需要在没有type
参数
elasticsearch.clients.suggest({
index: "randomindex",
body: {
"suggest": {
text: query,
completion: {
"field": "suggest_countries"
}
}
}
});
请参阅client.suggest()
call的官方文档,但没有type
参数。