【问题标题】:ElasticSearch Phrase Suggester returns no resultElasticSearch Phrase Suggester 不返回任何结果
【发布时间】:2017-04-24 11:16:32
【问题描述】:

我正在使用 ElasticSearch 5.1.2,作为 Heroku 的 Searchly 插件,带有 nodeJS 包 (https://github.com/elastic/elasticsearch-js)。 我正在尝试将菜肴名称与短语建议器匹配。 我相信我遵循了以下教程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 :-(
    }
  ]
}

感谢您的阅读,如有任何提示,我将不胜感激!

【问题讨论】:

    标签: elasticsearch elasticsearch-5


    【解决方案1】:

    我们遇到了同样的问题。结果是我们创建的映射和我们索引的数据之间的类型名称不匹配。例如,我们定义了agent 类型的映射,但我们的数据被作为agents 类型发送到索引。

    因此,不包括三元组和反向字段的新类型正在即时创建,因此字段上没有分析器来生成建议。

    希望这会有所帮助!

    【讨论】:

    • 嗨,我遇到了同样的问题。有关您如何最终解决此问题的任何指导?
    • 我们确保发送到 Elasticsearch 的所有数据的所有字段都已在架构中预先定义。
    猜你喜欢
    • 2015-12-07
    • 1970-01-01
    • 2015-11-19
    • 2020-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-28
    • 2017-12-09
    相关资源
    最近更新 更多