我有下一个查询:
GET /index/type/_search
{
"query": {
"filtered": {
"query": {
"match": {
"project": "ABC"
}
},
"filter": {
"bool": {
"must": [
{"term": {
"subtech": 2
}},
{
"term": {
"tech": 1
}
},
{
"term": {
"country": 1
}
}
]
}
}
}
}
}反应有50次点击。一切都很好,因为我有100份科技文档: 1份,国家1份,50份,科技1份,科技2份
当我用groovy编写这个查询时,我使用了最后一个项值:最后一个值subtech,hits = 50 -末后值技术,hits = 100最后值国家,hits = 100
查询:
client.search {
indices 'index'
types 'type'
source {
query {
filtered {
query {
match(project: 'ABC')
}
filter {
bool {
must {
term(subtech:2)
}
must {
term(tech:1)
}
must {
term(country:1)
}
}
}
}
}
}
}任何建议。
发布于 2015-07-28 17:10:22
支持的Groovy非常类似于JSON。
{
indices "index"
types "type"
source {
query {
filtered {
query {
match {
project = "ABC"
}
}
filter {
bool {
must [
{
term {
subtech = 2
}
},
{
term {
tech = 1
}
},
{
term {
country = 1
}
}
]
}
}
}
}
}
}在Groovy版本中,我注意到您的过滤器与JSON不同。具体来说,JSON中的术语用于subtech、tech和country。对于Groovy,您正在对agent、subtech和country进行过滤。
您还需要在must中重新分配bool,而不是给它分配一个过滤器数组。
must {
term(agent:1)
}
must {
term(subtech:2)
}
must {
term(country:1)
}请参考上面的示例,看看应该如何做。这里麻烦的是must的重新分配/调用。传入Map是有效的,尽管我个人建议更密切地镜像JSON。
https://stackoverflow.com/questions/31681827
复制相似问题