我使用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 api,我会编写类似以下内容:
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
}
}
我的查询不起作用!
最佳答案
我认为您在搜索请求中缺少几个json级别。我认为您必须在未指定查询的情况下才能使用该查询(它也可以是过滤器,甚至还有其他功能)。从groovy api引用中查看this example:
def search = node.client.search {
indices "test"
types "type1"
source {
query {
terms(test: ["value1", "value2"])
}
}
}
关于spring - 如何在ElasticSearch中编写搜索查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18193358/