【问题标题】:Querying multi-field in Elasticsearch for Exact string match在 Elasticsearch 中查询多字段以进行精确字符串匹配
【发布时间】:2016-01-21 05:34:18
【问题描述】:

我在 Elasticsearch 中有一个带有以下映射的字符串字段

"part_number":{"type":"string"}

因为我想在这个字段上进行精确字符串搜索,所以我添加了一个额外的字段,即not analyzed

{
  "properties": {
    "part_number": {
      "type": "string",
      "fields": {
        "raw": {
          "type": "string",
          "index": "not_analyzed"
        }
      }
    }
  }
}

现在,当我查询 part_number.raw 字段时,Elasticsearch 会返回结果。

_search?fields=part_number.raw&q=part_number:abc-000123

但是如何查询part_number.raw 字段。我想做类似的事情

_search?fields=part_number.raw&q=part_number.raw:abc-000123

但此查询返回空匹配。

我正在使用 python 弹性客户端。 提前致谢。

【问题讨论】:

    标签: python elasticsearch


    【解决方案1】:

    如果您要像这样查询part_number.raw 字段,则需要发送exact match 查询,即用转义的双引号括起来。

    _search?fields=part_number.raw&q=part_number.raw:\"abc-000123\"
                                                      ^           ^
                                                      |           |
                                                    add double quotes 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-21
      • 2016-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多