gpt4 book ai didi

elasticsearch - Elasticsearch查询以精确值匹配两个不同的字段

转载 作者:行者123 更新时间:2023-12-02 22:22:24 25 4
gpt4 key购买 nike

我想在我的Elasticsearch索引中找到一条记录,该记录应与值为“tyco-fire.com”的字段“connectorSpecific.hostname.keyword”和值为true的字段“hasForms”匹配。

以下是我的elasticsearch查询:

GET index1/_search
{
"query": {
"bool": {
"should": [
{ "match": { "connectorSpecific.hostname.keyword": "tyco-fire.com" }},
{ "match": { "hasForms": true }}
]
}
}
}

该查询返回的记录还具有值为false的字段“hasForms”。不知道为什么。我使用 bool(boolean) 值查询。任何帮助表示赞赏

最佳答案

如果要使两个约束都匹配,则应使用bool/filter(或bool/must也可以使用,但由于您正在进行精确匹配,因此根本不需要评分),如下所示:

GET index1/_search
{
"query": {
"bool": {
"filter": [
{ "match": { "connectorSpecific.hostname.keyword": "tyco-fire.com" }},
{ "match": { "hasForms": true }}
]
}
}
}

关于elasticsearch - Elasticsearch查询以精确值匹配两个不同的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49826587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com