您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在elasticsearch中的字符串数组中搜索精确字段

在elasticsearch中的字符串数组中搜索精确字段

问题是由于您正在使用该text字段和match查询

对匹配查询进行分析,并使用与索引时使用的搜索词相同的分析器,对于字段,这是标准分析器text。在您的情况下,如果在空白处打断文本,Landkreis Cloppenburg将创建两个标记landkreiscloppenburg同时创建索引和搜索时间,甚至cloppenburg匹配文档。

解决方案:使用keyword field

{
    "mappings": {
        "properties": {
            "location": {
                "type": "keyword"
            }
        }
    }
}

为两个文档建立索引,然后使用相同的搜索查询

{
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "location": {
                            "query": "Cloppenburg"
                        }
                    }
                }
            ]
        }
    }

}

 "hits": [
            {
                "_index": "location",
                "_type": "_doc",
                "_id": "2",
                "_score": 0.6931471,
                "_source": {
                    "location": "Cloppenburg"
                }
            }
        ]
其他 2022/1/1 18:24:23 有433人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶