ElasticSearch的新功能。
我在带有映射的Elastic搜索中的index
:myindex
下有文档:
http://host:port/myindex/_mapping
{
"mappings":{
"properties": {
"en_US": {
"type": "keyword"
}
}
}
}
假设我的3个文档如下所示:
{
"product": "p1",
"subproduct": "p1.1"
}
{
"product": "p1",
"subproduct": "p1.2"
}
{
"product": "p2",
"subproduct": "p2.1"
}
现在,我正在查询将单个子产品
p1.1
与产品p1
一起使用,如下所示,它工作正常:POST:http://host:port/myindex/_search
{
"query": {
"bool" : {
"must" : {
"term" : { "product" : "p1" }
},
"filter": {
"term" : { "subproduct" : "p1.1" }
}
}
}
}
我的问题是:
如何在一个_search查询中查询2个或多个子产品,例如产品
p1.1
下的suproducts p1.2
和p1
?查询应返回所有带有
p1.1
产品的子产品p1.2
和子产品p1
的列表。
最佳答案
只需将过滤器子句中的term
-query更改为terms
-query并搜索多个术语。
{
"query": {
"bool" : {
"must" : {
"term" : { "product" : "p1" }
},
"filter": {
"terms" : { "subproduct" : ["p1.1", "p1.2"] }
}
}
}
}
关于json - Elasticsearch :在一个查询中进行多项搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60444465/