ElasticSearch在包含破折号的bool过滤器上不返回结果

9nvpjoqh  于 2023-06-29  发布在  ElasticSearch
关注(0)|答案(1)|浏览(88)

我已经索引了2个对象(ES 1.5)

{
    tags: ["tag1","bla-bla"]
}

{
    tags: ["tag2"]
}

如果我提出这个要求:

{
    "query": {
        "filtered": {
            "filter": {
                "bool": {
                    "should":
                    [
                        {
                            "term": {
                                "tags": "bla-bla"
                            }
                        }
                    ]
                }
            }
        }
    }
}

弹性返回no result,因为tags字段中有**"-"**。
如果我搜索这个,它工作,我有1个结果:

...
    "term": {
         "tags": "tag1"
    }
...

有人能解释一下为什么当我在“标签”字段中放一个破折号(“-”)时,没有结果吗?

pdsfdshx

pdsfdshx1#

如果未指定,则自定义Elasticsearch将使用Standart Analyzer来分析字段。standart analyzer将删除标点符号(在您的情况下为-)并将您的术语标记为[ tag1bla ]。
您可以使用term vectors检查分析后的表单:

GET <index>/<type>/<id>/_termvectors?fields=tags

相关问题