elasticsearch - Elasticsearch通配符不匹配数字

标签 elasticsearch

我正在通过使用以下查询字符串来搜索elasticsearch索引:

curl -XGET 'http://localhost:9200/index/type/_search' -d '{
    "query": {                
                "query_string" : {
                    "default_field" : "keyword",
                    "query" : "file*.tif"
                }
    }
}'

关键字字段的架构如下:
"keyword" : {"type" : "string", "store" : "yes", "index" : "analyzed" }

以上查询的问题在于,在检索file001_copy.tif时,它不会检索诸如file001.tif之类的关键字的结果。 Match查询正在正确检索结果。这是Query_String的限制还是我缺少什么?

最佳答案

您可以通过分析要索引的字符串来查看问题

curl "localhost:9200/_analyze" -d "file001.tif" | python -mjson.tool
{
"tokens": [
    {
        "end_offset": 7, 
        "position": 1, 
        "start_offset": 0, 
        "token": "file001", 
        "type": "<ALPHANUM>"
    }, 
    {
        "end_offset": 11, 
        "position": 2, 
        "start_offset": 8, 
        "token": "tif", 
        "type": "<ALPHANUM>"
    }
]
}

curl "localhost:9200/_analyze" -d "file001_copy.tif" | python -mjson.tool
{
"tokens": [
    {
        "end_offset": 16, 
        "position": 1, 
        "start_offset": 0, 
        "token": "file001_copy.tif", 
        "type": "<ALPHANUM>"
    }
]
}

标准分析器file001.tif将 token 拆分为 file001 tif

但是file001_copy.tif不是。因此,当您搜索文件时,它只会命中file001_copy.tif,因为它是唯一符合您条件的文件(必须有一个包含"file" + 0个或多个字符以及“tif”的标记)

您可能希望将空格或关键字分析器与小写过滤器一起使用,以使其按您想要的方式工作。

关于elasticsearch - Elasticsearch通配符不匹配数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16836043/

相关文章:

elasticsearch - 在 ElasticSearch 中,如何检查一个字段是否存在等于某个值,或者该字段不存在?

Elasticsearch - 索引之间的关联计数?

elasticsearch - 带空格的短语中的通配符/正则表达式

elasticsearch - 您必须设置 ES_CLASSPATH 变量

django - 使用 elasticsearch-dsl DocType 映射配置

ElasticSearch:用匹配的搜索词标记文档

java - Elasticsearch 中的 log4j 升级

elasticsearch - Elasticsearch 嵌套match_phrase问题

elasticsearch - 无法在弹性中获得联接查询

elasticsearch - Spark 应用程序无法写入在 docker 中运行的 elasticsearch 集群