我使用Grails ElasticSearch插件,并希望使用以下查询:
"bool" : {
"must" : {
"term" : { "user" : "kimchy" }
},
"must_not" : {
"range" : {
"age" : { "from" : 10, "to" : 20 }
}
},
"should" : [
{
"term" : { "tag" : "wow" }
},
{
"term" : { "tag" : "elasticsearch" }
}
],
"minimum_should_match" : 1,
"boost" : 1.0
}使用Grails插件中的groovy,我将编写如下内容:
def res = userAgentIdentService.search() {
"bool" {
"must" {
term("user" : "kimchy" )
}
"must_not" {
"range" {
age("from" : 10, "to" : 20 }
}
}
"should" : [
{
term( "tag" : "wow" )
}
{
term("tag" : "elasticsearch" )
}
]
"minimum_should_match" = 1
"boost" = 1.0
}
}我的查询不起作用!
发布于 2013-08-13 08:18:11
我想你在你的搜索请求中遗漏了几个json级别。我认为如果不指定这是一个查询,您就不能使用该查询(它也可以是一个过滤器,甚至是其他一些东西)。查看groovy引用中的这个例子:
def search = node.client.search {
indices "test"
types "type1"
source {
query {
terms(test: ["value1", "value2"])
}
}
}https://stackoverflow.com/questions/18193358
复制相似问题