上下文化:我有这个查询,我在两个字段中搜索一个词,结果应该为我带来与通配符中插入的项相似的项。但最终我会得到一个搜索词列表…
当我只得到1个字符串时,我使用这个查询来搜索:
"query": {
"bool": {
"filter": [
{
"bool": {
"should": [
{
"wildcard": {
"shortName": "BAN*"
}
},
{
"wildcard": {
"name": "BAN*"
}
}
]
}
},
{
"range": {
"dhCot": {
"gte": "2022-04-11T00:00:00.000Z",
"lt": "2022-04-12T00:00:00.000Z"
}
}
}
]
}
},
"aggs": {
"articles_over_time": {
"date_histogram": {
"field": "dtBuy",
"interval": "1H",
"format": "yyyy-MM-dd:HH:mm:ssZ"
},
"aggs": {
"documents": {
"top_hits": {
"size": 100
}
}
}
}
}
}
但在某些情况下,我会得到一个字符串数组,比如["BANANA","APPLE","ORANGE"]
那么,我如何搜索与数组中的项完全匹配的项呢?这可能吗?
插入弹性的对象是这个:
{
"name": "BANANA",
"priceDay": 1,
"priceWeek": 3,
"variation": 2,
"dataBuy":"2022-04-11T11:01:00.585Z",
"shortName": "BAN"
}
如果要搜索与数组中的项完全匹配的项,可以使用术语query
{
"query": {
"terms": {
"name": ["BANANA","APPLE","ORANGE"]
}
}
}
根据您的用例,您可以在现有的查询中包括术语查询,在should
子句或must
子句中。