在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
子句或should
带minimum_should_match
参数的子句。您可以从这里更多地参考。
为以上各列创建的映射为:
"mappings" : {
"properties" : {
"column1" : {
"type":"text"
},
"column2" : {
"type":"text"
},
"column3" : {
"type":"text"
},
"column4" : {
"type":"text"
}
}
}
您可以通过两种方式获取搜索结果:
must
带有match
查询的子句中传递所有搜索值。Match
默认情况下使用OR运算符。因此,它将匹配任何column4
值与任何“ abc d”匹配的文档。您可以从此处了解匹配查询的默认运算符。 {
"_source": [
"column1",
"column2",
"column3"
],
"query": {
"match": {
"column4": "a b c d"
}
}
}
minimum_should_match
参数将其限制为仅一个匹配项。 {
"_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] 删除。
我来说两句