ElasticSearch Phrase Suggestester does not return a result

I am using ElasticSearch 5.1.2 as Heroku Searchly plugin with nodeJS package ( https://github.com/elastic/elasticsearch-js ). I am trying to match dish names with Phrase Suggestester. I believe that I followed the letter in the next tutorial https://www.elastic.co/guide/en/elasticsearch/reference/5.1/search-suggesters-phrase.html

I can see in Searchly's search bar that my store contains data. However, my queries never return any result even when searching for the exact phrase.

Here is my setup (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'
  }

And here is my request:

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: ']'
        }
}

Here is what I get when I look for "potato chips with strawberry jam":

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 :-(
    }
  ]
}

Thanks for reading, I would really appreciate any hint!

+4
1

. , , , . , , agent, agents.

, " ", , .

, !

0

Source: https://habr.com/ru/post/1675512/


All Articles