elasticsearch 大小写不敏感不适用于具有西里尔语数据的通配符字段类型

q9rjltbz  于 2023-03-07  发布在  ElasticSearch
关注(0)|答案(1)|浏览(111)

当您有一个索引,其中的字段类型为通配符,并填充了西里尔字母数据,然后您使用case_sensitive执行通配符查询时:true,未找到文档。
注:目前在ES版本7.17.8中
测试示例:

PUT /index
{
  "mappings": {
    "properties": {
      "name": {
        "type": "wildcard"
      }
    }
  }
}

POST /index/_doc/1
{
  "name": "ТЕСТ"
}

POST /index/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "wildcard": {
            "name": {
              "value": "*Тест*",
              "case_insensitive": true
            }
          }
        }
      ]
    }
  }
}

我试图搜索修复,但找不到任何东西。有什么可以帮助解决这个问题吗?
注意:索引数据和查询数据都是西里尔字符。
西里尔文:
切塞茨-0xd0a2d095d0a1d0a2
特切什特-0xd0a2d0b5d181d182
而拉丁语则是:
TECT-0x54454354
总人数-0x54656374

w7t8yxp5

w7t8yxp51#

    • 编辑:**如果您使用ngram tokenizer,则在搜索时无需添加通配符"*"。
PUT /test_ngram_analyzer
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "ngram_tokenizer",
          "filter": "lowercase"
        }
      },
      "tokenizer": {
        "ngram_tokenizer": {
          "type": "ngram",
          "min_gram": 3,
          "max_gram": 10
        }
      }
    },
    "index.max_ngram_diff": 10
  },
  "mappings": {
    "properties": {
      "test": {
        "type": "text",
        "analyzer": "my_analyzer"
      }
    }
  }
}

POST /test_ngram_analyzer/_doc/1
{
  "test": "ТЕСТ"
}
POST /test_ngram_analyzer/_doc/2
{
  "test": "TECT"
}

POST /test_ngram_analyzer/_search
{
  "query": {
    "match": {
      "test": "Тес"
    }
  }
}

如果您使用ngram分析器,则在搜索时不需要添加通配符"*"。

要了解它的工作原理,可以使用analyze aPI

POST test_ngram_analyzer/_analyze
{
  "analyzer": "my_analyzer", 
  "text" : ["TECT", "ТЕСТ"]
}

您的小写"T"有问题:)。
Тест =〉tect

POST /test_index_musab/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "wildcard": {
            "name": {
              "value": "Tect",
              "case_insensitive": true
            }
          }
        }
      ]
    }
  }
}

https://www.elastic.co/guide/en/elasticsearch/reference/7.17/keyword.html#wildcard-field-type
更多信息的一些注解:

    • 限制**

通配符字段与关键字字段一样未标记化,因此不支持依赖于单词位置的查询(如短语查询)。运行通配符查询时,将忽略任何重写参数。得分始终为常数。

相关问题