ElasticSearch的新功能。
我在带有映射的弹性搜索中的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查询中查询suproductsp1.1
和p1.2
under product的2个或更多子产品p1
?查询应返回所有子产品p1.1
和p1.2
带有p1
产品的子产品的列表。
只需term
将过滤器子句中的terms
-query更改为-query并搜索多个术语。
{
"query": {
"bool" : {
"must" : {
"term" : { "product" : "p1" }
},
"filter": {
"terms" : { "subproduct" : ["p1.1", "p1.2"] }
}
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句