首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ElasticSearch短语建议程序不返回任何结果

ElasticSearch短语建议程序不返回任何结果
EN

Stack Overflow用户
提问于 2017-04-24 19:16:33
回答 1查看 363关注 0票数 3

我使用的是带有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):

代码语言:javascript
复制
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'
  }

下面是我的问题:

代码语言:javascript
复制
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: ']'
        }
}

这是我搜索“草莓酱薯片”时得到的结果:

代码语言:javascript
复制
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 :-(
    }
  ]
}

感谢您的阅读,我将非常感谢您的任何提示!

EN

回答 1

Stack Overflow用户

发布于 2017-08-11 00:16:24

我们也遇到了同样的问题。事实证明,我们正在创建的映射和我们正在索引的数据之间的类型名称不匹配。例如,我们定义了agent类型的映射,但是我们的数据是以agents类型发送到索引的。

因此,新的类型是动态创建的,不包括三元组和反转字段,所以字段上没有分析器来产生建议。

希望这能有所帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43586632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档