我正在尝试使用Elasticsearch查询DSL编写下面提到的SQL查询,但是我无法获得与SQL查询相同的结果。任何人都可以通过以下查询的bool查询来帮助e。我正在使用elasticsearch 2.1.1版本。
id.eq(someId)
.and(
(anotherId.eq(another).and(node.eq(node)))
.or
(domain.in(List))
)
这就是我尝试过的。如果这是正确的,我如何在Java DSL中编写相同的查询?
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term": {
"id": 1
}
}
]
}
},
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"term": {
"anotherId": "ss"
}
},
{
"term": {
"node": "ss"
}
}
]
}
},
{
"bool": {
"must": [
{
"terms": {
"domain" : [ "cc", "cc" ]
}
}
]
}
}
]
}
}
}
}
}
最佳答案
这是在ES 2.1.1中执行此操作的正确方法
{
"query": {
"bool": {
"filter": [
{
"term": {
"id": 1
}
},
{
"bool": {
"should": [
{
"bool": {
"filter": [
{
"term": {
"anotherId": "ss"
}
},
{
"term": {
"node": "ss"
}
}
]
}
},
{
"terms": {
"domain": [
"cc",
"cc"
]
}
}
]
}
}
]
}
}
}
关于elasticsearch - 带有多个和/或流的Elasticsearch Bool查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37060158/