ElasticSearch不区分大小写的QUERY_STRING通配符查询

uxh89sit  于 2022-10-06  发布在  ElasticSearch
关注(0)|答案(2)|浏览(288)

在我的ESMap中,我有一个‘uri’字段,它当前设置为NOT_ANALYSED,并且我不允许更改Map。我想使用如下的QUERY_STRING查询来搜索URI部分(这个ES查询是自动生成的,这就是为什么它有点复杂,但我们只关注QUERY_STRING部分)

{
  "sort": [{"updated": {"order": "desc"}}], 
   "query": {
     "bool": {
       "must":[{
         "query_string": {
           "query":"*w3\.org\/2014\/01\/a*", 
           "lowercase_expanded_terms": true, 
           "default_field": "uri"
         }
       }], 
       "minimum_number_should_match": 1
     }
   }, "size": 50}

现在它通常可以工作,但我已经存储了以下url(虚构的url):http://w3.org/2014/01/Abc.html,由于A-a的差异,此查询不会将其带回。将扩展术语设置为FALSE也不能解决这个问题。我应该怎么做才能使此查询不区分大小写?

提前感谢您的帮助。

xmq68pz9

xmq68pz91#

从文档上看,您似乎需要一个新的分析器,它首先转换为小写,然后才能运行搜索。你试过了吗?http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/sorting-collations.html

据我所知,您的模式LOWERCASE_EXPENDED_TERMS只适用于扩展,而不适用于常规单词http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.htmllowercase_expanded_terms Whether terms of wildcard, prefix, fuzzy, and range queries are to be automatically lower-cased or not (since they are not analyzed). Default it true

ctzwtxfj

ctzwtxfj2#

尝试使用match query而不是query string

{
"sort": [
    {
        "updated": {
            "order": "desc"
        }
    }
],
"query": {
    "bool": {
        "must": [
            {
                "match": {
                    "uri": "*w3\.org\/2014\/01\/a*"
                }
            }
        ]
    }
},
"size": 50
}

不分析Query string查询,但分析匹配查询。

相关问题