【问题标题】:Elasticsearch exact match of specific field(s)特定字段的 Elasticsearch 精确匹配
【发布时间】:2014-09-29 19:44:08
【问题描述】:

我正在尝试按特定字段过滤我的弹性搜索索引,确切地说是“国家”字段。但是,我不断收到大量不准确的其他结果(其他国家/地区)。

请有人指出正确的方向。

我尝试了以下搜索:

GET http://127.0.0.1:9200/decision/council/_search
{
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "country": "Algeria"
        }
      }
    }
  }
}

这是一个示例文档:

{
  "_index": "decision",
  "_id": "54290140ec882c6dac5ae9dd",
  "_score": 1,
  "_type": "council",
  "_source": {
    "document": "DEV DOCUMENT"
    "id": "54290140ec882c6dac5ae9dd",
    "date_updated": 1396448966,
    "pdf_file": null,
    "reported": true,
    "date_submitted": 1375894031,
    "doc_file": null,
    "country": "Algeria"
  }
}

【问题讨论】:

  • 结果不准确是什么意思?能举个例子吗?
  • @femtoRgon 所以我希望搜索返回带有“国家”字段的文档:“阿尔及利亚” - 但是,如果我运行搜索,我一直在这样做返回包含所有不同国家的文档,例如“国家”:“斯里兰卡”。
  • 好吧,这似乎没有多大意义。你能运行an explain query,看看它在哪里找到这些文档的匹配项吗?
  • @femtoRgon - 我添加了:“explain”:true, - 在搜索中的“查询”上方 - 输出与不存在时没有区别。
  • 有趣的是,如果我进行这样的搜索:127.0.0.1:9200/decision/council/_search?q=country:Algeria' 它会返回正确的结果......怎么样?为什么?

标签: elasticsearch lucene exact-match


【解决方案1】:

您可以改用 match_phrase 查询

POST http://127.0.0.1:9200/decision/council/_search
{
   "query" : {
      "match_phrase" : { "country" : "Algeria"}
            }
}

【讨论】:

  • 感谢您的回复 - 刚刚尝试了上述方法,仍然返回其他国家/地区。
  • 对不起,我的意思是 Post 不是 GET
  • 不完全是我需要的:如果一个或多个单词匹配,它将返回,例如old titlold title1old title 匹配
猜你喜欢
  • 1970-01-01
  • 2017-03-02
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-10
相关资源
最近更新 更多