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查询中查询2个或多个子产品,例如产品p1.1
下的suproducts p1.2
和p1
?
查询应返回所有子产品p1.1
和带有p1.2
产品的子产品p1
的列表。
答案 0 :(得分:0)
只需将过滤器子句中的term
查询更改为terms
查询,然后搜索多个词。
{
"query": {
"bool" : {
"must" : {
"term" : { "product" : "p1" }
},
"filter": {
"terms" : { "subproduct" : ["p1.1", "p1.2"] }
}
}
}
}