【问题标题】:distinct a field without case sensetive in Elasticsearsh在 Elasticsearch 中区分不区分大小写的字段
【发布时间】:2021-08-31 10:33:07
【问题描述】:

我们要求区分区分大小写的字段(例如“CIty”和“ciTy”必须在一个组中)。 我可以在 Elasticsearch 中通过此功能实现查询吗?

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: elasticsearch distinct case-sensitive


【解决方案1】:

这个问题需要在索引时解决。使用normalizer进行索引时可以将标记转换为小写

{
  "settings": {
    "analysis": {
      "normalizer": {
        "my_normalizer": {
          "type": "custom",
          "filter": [
            "lowercase"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "city": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "normalizer": "my_normalizer"
          }
        }
      }
    }
  }
}

会给

 "aggregations" : {
    "cities" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "a",
          "doc_count" : 2
        }
      ]
    }
  }

“A”和“a”都被视为单个值

【讨论】:

    猜你喜欢
    • 2023-03-23
    • 2014-02-17
    • 1970-01-01
    • 2020-02-18
    • 1970-01-01
    • 2015-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多