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

在Elasticsearch中使用“ AND”运算符使用数组进行多字段搜索

在Elasticsearch中使用“ AND”运算符使用数组进行多字段搜索

显示您的映射类型,但是我怀疑您的tags字段是一个简单的string字段,如下所示:

{
    "your_type" : {
        "properties" : {
            "tags" : {
                "type" : "string"
            }
        }
    }
}

在这种情况下,ES会tags在索引编制时将字段中的所有标签“扁平化” ,如下所示:

tags: "stuff", "like", "this", "that"

即,这就是为什么在查询“东西”时得到结果的原因,因为该tags字段包含两个单词。

前进的方法是制作tags一个嵌套的对象类型,像这样

{
    "your_type" : {
        "properties" : {
            "tags" : {
                "type" : "nested",
                "properties": {
                    "tag" : {"type": "string" }
                }
            }
        }
    }
}

您需要重新索引数据,但至少查询tags: "stuff that"将不再返回任何内容。您的标记令牌将按照您的期望“保持在一起”。试试看。

其他 2022/1/1 18:16:35 有481人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

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

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

请先登录

推荐问题


联系我
置顶