-
-
Notifications
You must be signed in to change notification settings - Fork 128
Description
Example code:
const bodybuilder = require('bodybuilder');
let body = bodybuilder();
body.query('bool', b => b
.filter('term', 'field1', x)
.filter('term', 'field2', x)
.orFilter('term', 'field3', x));
body.query('bool', b => b
.filter('term', 'field1', x)
.filter('term', 'field2', x)
.orFilter('term', 'field3', x));Makes perfect, valid query:
{
"query": {
"bool": {
"must": [
{
"bool": {
"filter": {
"bool": {
"must": [
{
"term": {
"field1": 1
}
},
{
"term": {
"field2": 2
}
}
],
"should": [
{
"term": {
"field3": 3
}
}
]
}
}
}
},
{
"bool": {
"filter": {
"bool": {
"must": [
{
"term": {
"field4": 10
}
},
{
"term": {
"field5": 20
}
}
],
"should": [
{
"term": {
"field6": 30
}
}
]
}
}
}
}
]
}
}
}
Change filters to queries:
const bodybuilder = require('bodybuilder');
let body = bodybuilder();
body.query('bool', b => b
.query('term', 'field1', x)
.query('term', 'field2', x)
.orQuery('term', 'field3', x));
body.query('bool', b => b
.query('term', 'field1', x)
.query('term', 'field2', x)
.orQuery('term', 'field3', x));And built query is invalid:
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[bool] query does not support [query]",
"line": 7,
"col": 22
}
],
"type": "parsing_exception",
"reason": "[bool] query does not support [query]",
"line": 7,
"col": 22
},
"status": 400
}
{
"query": {
"bool": {
"must": [
{
"bool": {
"query": {
"bool": {
"must": [
{
"term": {
"field1": 1
}
},
{
"term": {
"field2": 2
}
},
{
"term": {
"field3": 3
}
}
]
}
}
}
},
{
"bool": {
"query": {
"bool": {
"must": [
{
"term": {
"field4": 10
}
},
{
"term": {
"field5": 20
}
},
{
"term": {
"field6": 30
}
}
]
}
}
}
}
]
}
}
}
cultron
Metadata
Metadata
Assignees
Labels
No labels