【问题标题】:filter with special character in ElasticSearch 6.0.0在 ElasticSearch 6.0.0 中使用特殊字符过滤
【发布时间】:2021-03-25 12:11:54
【问题描述】:

我正在尝试过滤所有包含“@”、“.”、“/”等特殊字符的数据。但无法成功。

我愿意获取包含 @ 或点 (.) 的城市,所以我需要一个查询来为我提供包含特殊字符的输出。

我是 Elasticsearch 查询的新手。所以请帮助我。

谢谢

下面是索引:

  "hits" : {
    "total" : 4,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "student",
        "_type" : "data",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "name" : "Mirja",
          "city" : "pune @ bandra",
          "contact number" : 9723124343
        }
      },
      {
        "_index" : "student",
        "_type" : "data",
        "_id" : "4",
        "_score" : 1.0,
        "_source" : {
          "name" : "Rohan",
          "city" : "BBSR /. patia",
          "contact number" : 9723124343
        }
      },
      {
        "_index" : "student",
        "_type" : "data",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "name" : "Diya",
          "city" : "pune_bandra",
          "contact number" : 9723124343
        }
      }
      }
    ]
  }
}```

【问题讨论】:

    标签: elasticsearch elasticsearch-query


    【解决方案1】:

    您需要检查您所在城市字段的分析器。如果它是标准分析器,它将在创建标记时删除特殊字符。而是在城市字段上使用以下映射并使用常规匹配查询进行搜索

    PUT test_index
        {
          "mappings": {
            "properties": {
              "city": {
                "type": "text",
                "analyzer": "custom_analyzer"
              }
            }
          },
          "settings": {
            "analysis": {
              "analyzer": {
                "custom_analyzer": {
                  "type": "custom",
                  "filter": [
                    "lowercase"
                  ],
                  "tokenizer": "whitespace"
                }
              }
            }
          }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-08
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多