如何查找elasticsearch中与字段和值匹配的所有文档?
问题描述:
我有一个索引users
与user
类型。映射是动态的。现在user
HS一个结构如下:如何查找elasticsearch中与字段和值匹配的所有文档?
"user": {
"nested": {
"one":51
},
"other": {
"two":"hi!"
},
"three":false
}
我需要找到具有other.two
字段值hi
或具有价值false
three
领域的所有用户。例如。具有other.two
的用户必须具有hi
值或three
字段值为false
。如何从弹性搜索中选择这个?
我曾尝试:
GET /users/user/_search
{"query": {"match": {"other.two": "hi"}}}
返回用户的我,但
GET /users/user/_search
{"query": {"match": {"other.two": "hi", "three":false}}}
返回我SearchPhaseExecutionException
。
如何结合几个字段和值进行搜索?
答
由于@rvheddeg上述建议,这里是为我的作品查询:
{
"query": {
"bool": {
"should": [
{ "match": { "other.two": "hi" }},
{ "match": { "three": false }}
],
"minimum_should_match": 1
}
}
}