【问题标题】:Elasticsearch completion : strange behavior when multiple matches per documentElasticsearch完成:每个文档有多个匹配项时的奇怪行为
【发布时间】:2019-11-30 04:08:24
【问题描述】:

当我在 ElasticSearch 文档 (https://www.elastic.co/guide/en/elasticsearch/reference/6.7/search-suggesters-completion.html) 中描述的建议中使用完成类型时,我无法获得所有匹配的单词(每个文档我只能得到一个匹配的单词)

我在我的 ElasticSearch 6.7.2(这是 AWS 目前可用的最新版本)上测试以下命令:

如果存在则删除索引

curl http://localhost:9200/test -H 'Content-Type: application/json' -X DELETE

创建索引

curl http://localhost:9200/test -H 'Content-Type: application/json' -X PUT -d '
{
  "mappings": {
    "page": {
      "properties": {
        "completion_terms": {
          "type": "completion"
        }
      }
    }
  }
}
'

索引文档

curl http://localhost:9200/test/_doc/1 -H 'Content-Type: application/json' -X PUT -d '
{
"completion_terms": ["restaurant", "restauration", "réseau"]
}'

检查文档是否存在

curl http://localhost:9200/test/_doc/1 -H 'Content-Type: application/json'

使用补全

curl -X GET "localhost:9200/test/_search?pretty=true" -H 'Content-Type: application/json' -d'
{
  "_source": ["suggestExact"],
  "suggest": {
      "suggestExact" : {
          "prefix" : "res",
          "completion" : {
              "field" : "completion_terms"
          }
      }
  }
}
'

结果是:

{
  "took" : 6,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "suggest" : {
    "suggestExact" : [
      {
        "text" : "res",
        "offset" : 0,
        "length" : 3,
        "options" : [
          {
            "text" : "restaurant",
            "_index" : "test",
            "_type" : "page",
            "_id" : "1",
            "_score" : 1.0,
            "_source" : { }
          }
        ]
      }
    ]
  }
}

我想获取所有匹配的单词(这里,每个文档我最多得到一个结果)

在示例中,缺少“restauration”和“réseau”

我做错了吗?

【问题讨论】:

    标签: elasticsearch aws-elasticsearch


    【解决方案1】:

    经过多次搜索,我发现这是预期的行为(即“建议文件”,而不是“建议条款”)

    尤其是https://github.com/elastic/elasticsearch/issues/31738

    但是,即使使用似乎是正确方式的术语建议者 (https://www.elastic.co/guide/en/elasticsearch/reference/6.7/search-suggesters-term.html),我仍然无法实现“建议条款”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-05
      • 1970-01-01
      • 1970-01-01
      • 2014-06-23
      • 2016-07-13
      相关资源
      最近更新 更多