您的一个查询要求区分大小写,而第二个查询则不区分大小写。因此,我建议您将子字段用作哈希字段。您的主字段将使用小写分析器进行分析,一个主字段将存储原始数据,即确切的哈希。因此,您的索引如下所示:
PUT /test{ "settings": { "number_of_shards": "1", "number_of_replicas": "0", "analysis": { "analyzer": { "custom_lowercase": { "filter": [ "lowercase" ], "type": "custom", "tokenizer": "keyword" } } } }, "mappings": { "_doc": { "properties": { "hash": { "type": "text", "analyzer": "custom_lowercase", "fields": { "keyword": { "type": "keyword" } } } } } }}查询以检查是否存在哈希“ ErTg1Qh”(区分大小写)
POST /test/_doc/_search{ "query": { "match": { "hash.keyword": "ErTg1Qh" } }}查询以查找子字符串s中包含的哈希
POST /test/_doc/_search{ "query": { "query_string": { "query": "*tg*" } }}


