ELK 查询指定名称列表 return 所有名称与列表中的名称匹配的记录
ELK query specifying a list of names to return all records with names matching the names in the list
当我构建 ELK 查询并指定如下条件时:
'query_string' : {
'query': 'product.name: "' + productName + '"'
+ ' AND cost: xxxx'
}
}
它 returns product.name 的记录与变量 productName 中的值匹配,但是如果我想指定一个 productNames[] 列表,并且该列表中包含产品名称的所有记录都需要返回,如何修改上面的查询?
您可以使用 product.name:(productA OR productB OR productC)
。查看 query string syntax 文档。
如果您不需要使用 query_string
查询,您也可以使用 bool query with a terms query,如下所示:
{
"query": {
"bool": {
"must": [
{
"terms": {
"product.name": ["productA", "productB", "productC", ...]
}
},
{
"match": {
"cost": "xxxx"
},
{
"match": {
"otherField": "yyyy"
},
...
}
}
}
}
当我构建 ELK 查询并指定如下条件时:
'query_string' : {
'query': 'product.name: "' + productName + '"'
+ ' AND cost: xxxx'
}
}
它 returns product.name 的记录与变量 productName 中的值匹配,但是如果我想指定一个 productNames[] 列表,并且该列表中包含产品名称的所有记录都需要返回,如何修改上面的查询?
您可以使用 product.name:(productA OR productB OR productC)
。查看 query string syntax 文档。
如果您不需要使用 query_string
查询,您也可以使用 bool query with a terms query,如下所示:
{
"query": {
"bool": {
"must": [
{
"terms": {
"product.name": ["productA", "productB", "productC", ...]
}
},
{
"match": {
"cost": "xxxx"
},
{
"match": {
"otherField": "yyyy"
},
...
}
}
}
}