我使用的是带有nodeJS包(https://github.com/elastic/elasticsearch-js)的ElasticSearch 5.1.2,作为Heroku的Searchly插件。我正在尝试将菜名与短语Suggester相匹配。我相信我遵循了下面的教程https://www.elastic.co/guide/en/elasticsearch/reference/5.1/search-suggesters-phrase.html
我可以在Searchly仪表板中看到我的存储包含数据。然而,我的查询永远不会返回任何结果,即使在搜索确切的短语时也是如此。
下面是我的设置(CoffeeScript):
elasticSearchClient.indices.exists index: 'dishes'
.then (indexExists) ->
if indexExists
elasticSearchClient.indices.delete index: 'dishes'
.then () ->
elasticSearchClient.indices.create index: 'dishes'
.then () ->
elasticSearchClient.indices.close index: 'dishes'
.then () ->
elasticSearchClient.indices.putSettings {
index: 'dishes'
body:
settings:
number_of_shards: 1
analysis:
filter:
shingle:
type: 'shingle',
min_shingle_size: 2
max_shingle_size: 3
analyzer:
trigram:
type: 'custom',
tokenizer: 'standard',
filter: ['standard', 'shingle']
reverse:
type: 'custom',
tokenizer: 'standard',
filter: ['standard', 'reverse']
}
.then () ->
elasticSearchClient.indices.open index: 'dishes'
.then () ->
elasticSearchClient.indices.putMapping {
index: 'dishes'
type: 'dishes'
body:
properties:
dishNameMatching:
type: 'text'
fields:
trigram:
type: 'text'
analyzer: 'trigram'
reverse:
type: 'text'
analyzer: 'reverse'
name:
type: 'string'
index: 'no'
flavorId:
type: 'string'
index: 'no'
}下面是我的问题:
elasticSearchClient.suggest {
index: 'dishes'
body:
text: myText
dishSuggester:
phrase:
field: 'dishNameMatching.trigram'
size: options.limit or 5
gram_size: 3
direct_generator: [
field: 'dishNameMatching.trigram'
suggest_mode: 'always'
]
highlight: {
pre_tag: '['
post_tag: ']'
}
}这是我搜索“草莓酱薯片”时得到的结果:
results: {
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"dishSuggester": [
{
"text": "potato chips with strawberry jam",
"offset": 0,
"length": 49,
"options": [] # Should be some results here :-(
}
]
}感谢您的阅读,我将非常感谢您的任何提示!
发布于 2017-08-11 00:16:24
我们也遇到了同样的问题。事实证明,我们正在创建的映射和我们正在索引的数据之间的类型名称不匹配。例如,我们定义了agent类型的映射,但是我们的数据是以agents类型发送到索引的。
因此,新的类型是动态创建的,不包括三元组和反转字段,所以字段上没有分析器来产生建议。
希望这能有所帮助!
https://stackoverflow.com/questions/43586632
复制相似问题