我使用ElasticSearch 5.1.2作为Heroku的Searchly插件,使用nodeJS包(https://github.com/elastic/elasticsearch-js)。 我正在尝试将菜肴名称与Phrase Suggester相匹配。 我相信我接着写了以下教程https://www.elastic.co/guide/en/elasticsearch/reference/5.1/search-suggesters-phrase.html
我可以在Searchly仪表板中看到我的商店包含数据。 然而,即使在搜索确切的短语时,我的查询也不会返回任何结果。
这是我的设置(CoffeeScript):
<link href="https://cdnjs.cloudflare.com/ajax/libs/awesomplete/1.1.1/awesomplete.min.css" rel="stylesheet"/>
<input id="myinput" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/awesomplete/1.1.1/awesomplete.min.js"></script>
这是我的疑问:
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'
}
这是我在寻找带有草莓酱的#34;马铃薯片时得到的结果&#34;:
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: ']'
}
}
感谢您的阅读,我将非常感谢任何暗示!