在Kibana / ElasticSearch中搜索多个字段

GTpy

在SQL中我有

select Column1 , column2, column3 from Table where Column4 in ['a','b','c','d']

我试图在Kibana中实现SQL语句,在编写In条件时面临挑战。

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "field1": "X"
          }
        },
        {
          "term": {
            "field2": "Z"
          }
        }
      ],

    }
  }
}
普雷纳

为了获得上述结果,可以使用bool查询must子句或shouldminimum_should_match参数的子句您可以从这里更多地参考

为以上各列创建的映射为:

制图

"mappings" : {
        "properties" : {
            "column1" : {
                "type":"text"
            },
            "column2" : {
                "type":"text"
            },
            "column3" : {
                "type":"text"
            }, 
            "column4" : {
                "type":"text"
            }
        }
    }

您可以通过两种方式获取搜索结果:

  1. 您可以在must带有match查询的子句中传递所有搜索值Match默认情况下使用OR运算符。因此,它将匹配任何column4值与任何“ abc d”匹配的文档您可以从此处了解匹配查询的默认运算符

查询:

    {
    "_source": [
        "column1",
        "column2",
        "column3"
    ],
    "query": {
        "match": {
            "column4": "a b c d"
        }
    }
}
  1. 您还可以对每个值都使用匹配查询子句。并使用minimum_should_match参数将其限制为仅一个匹配项

查询2:

 {
     "_source": ["column1", "column2", "column3"],
    "query" : {
        "bool" : {
            "should" : [
                {
                    "match" : {
                        "column4" : "a"
                    }
                },
                {
                    "match" : {
                        "column4" : "b"
                    }
                },
                {
                    "match" : {
                        "column4" : "c"
                    }
                },
                {
                    "match" : {
                        "column4" : "d"
                    }
                }
            ],
            "minimum_should_match" : "1"
        }
    }
}

对于您拥有的数据类型,column4可以先查询。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章