谁能解释一下为什么这个elasticsearch语法是不正确的?我正在努力理解基本语法
这是"query": {
"filtered": {
"filter": {
"bool" : {
"should": {
"terms": {
"headline":["aut"]
}
},
"must": {
"range": {
"date_at" : {
"gt": "1900-01-01 00:00:00",
"lt": "1980-01-01 00:00:00"
}
}
}
}
}
}
}
但是,这个查询不起作用
"query": {
"filtered": {
"filter": {
"bool" : {
"should": {
"terms": {
"headline":["aut"]
}
},
"must": {
"range": {
"date_at" : {
"gt": "1900-01-01 00:00:00",
"lt": "1980-01-01 00:00:00"
}
},
"term": {
"headline": "et"
}
}
}
}
}
}
在布尔值"必须"内添加"term"子句会导致语法错误,所有分片都被破坏等…问题似乎是我想在两个不同的bool中使用相同的索引两次,特别是
标题必须包含"foo"
标题应该包含"bar"
有可能吗?
你试过吗?
{
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"terms": {
"headline": [
"aut"
]
}
}
],
"must": [
{
"range": {
"date_at": {
"gt": "1900-01-01 00:00:00",
"lt": "1980-01-01 00:00:00"
}
}
},
{
"term": {
"headline": "et"
}
}
]
}
}
}
}
}
这可能是你想要做的事情的直接解释,但这可能是你真正需要的:
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"range": {
"date_at": {
"gt": "1900-01-01 00:00:00",
"lt": "1980-01-01 00:00:00"
}
}
},
{
"term": {
"headline": "et"
}
}
]
}
}
}
}
}
下面是一些我用来摆弄它的代码:
http://sense.qbox.io/gist/ea16ff321397c2187ef503541019d52c564b7460