Grails-ElasticSearch-QueryParsingException[[index]没有为[query]]注册查询;用橡皮筋;不过,JSON通过curl工作得很好
我一直在从事一个Grails项目,与ElasticSearch(v20.6)合作,定制了ElasticSearch Grails插件(以支持geo_point索引:v20.6) 一直在尝试进行过滤搜索,同时使用脚本_字段(计算距离)。以下是从GXContentBuilder生成的JSON的闭包: 关闭Grails-ElasticSearch-QueryParsingException[[index]没有为[query]]注册查询;用橡皮筋;不过,JSON通过curl工作得很好,grails,elasticsearch,Grails,elasticsearch,我一直在从事一个Grails项目,与ElasticSearch(v20.6)合作,定制了ElasticSearch Grails插件(以支持geo_point索引:v20.6) 一直在尝试进行过滤搜索,同时使用脚本_字段(计算距离)。以下是从GXContentBuilder生成的JSON的闭包: 关闭 records = Domain.search(searchType:'dfs_query_and_fetch'){ query {
records = Domain.search(searchType:'dfs_query_and_fetch'){
query {
filtered = {
query = {
if(queryTxt){
query_string(query: queryTxt)
}else{
match_all {}
}
}
filter = {
geo_distance = {
distance = "${userDistance}km"
"location"{
lat = latlon[0]?:0.00
lon = latlon[1]?:0.00
}
}
}
}
}
script_fields = {
distance = {
script = "doc['location'].arcDistanceInKm($latlon)"
}
}
fields = ["_source"]
}
GXContentBuilder生成的查询JSON:
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "5km",
"location": {
"lat": "37.752258",
"lon": "-121.949886"
}
}
}
}
},
"script_fields": {
"distance": {
"script": "doc['location'].arcDistanceInKm(37.752258, -121.949886)"
}
},
"fields": ["_source"]
}
使用curl方式的JSON查询工作得非常好。但当我尝试从Groovy代码执行它时,我的意思是(取自ElasticSearchService.Groovy),其中request是SearchRequest实例:
elasticSearchHelper.withElasticSearch { Client client ->
def response = client.search(request).actionGet()
}
它抛出以下错误:
Failed to execute phase [dfs], total failure; shardFailures {[1][index][3]: SearchParseException[[index][3]: from[0],size[60]: Parse Failure [Failed to parse source [{"from":0,"size":60,"query_binary":"eyJxdWVyeSI6eyJmaWx0ZXJlZCI6eyJxdWVyeSI6eyJtYXRjaF9hbGwiOnt9fSwiZmlsdGVyIjp7Imdlb19kaXN0YW5jZSI6eyJkaXN0YW5jZSI6IjVrbSIsImNvbXBhbnkuYWRkcmVzcy5sb2NhdGlvbiI6eyJsYXQiOiIzNy43NTIyNTgiLCJsb24iOiItMTIxLjk0OTg4NiJ9fX19fSwic2NyaXB0X2ZpZWxkcyI6eyJkaXN0YW5jZSI6eyJzY3JpcHQiOiJkb2NbJ2NvbXBhbnkuYWRkcmVzcy5sb2NhdGlvbiddLmFyY0Rpc3RhbmNlSW5LbSgzNy43NTIyNTgsIC0xMjEuOTQ5ODg2KSJ9fSwiZmllbGRzIjpbIl9zb3VyY2UiXX0=","explain":true}]]]; nested: QueryParsingException[[index] No query registered for [query]]; }
如果我只使用filtered={…}script\u fields={…}
但它不返回计算出的距离,则上述闭包可以工作
有人有过类似的问题吗
提前感谢:)
在这里,我可能有点不好意思指出一个显而易见的问题:p您可以使用普通的Groovy DSL而不是每次都定义闭包吗<代码>查询{已筛选的{…}脚本_字段{…}(删除
=
)我执行了该操作,但出现了相同的错误。另外,正确的dsl是query{}只封装过滤的{}部分&script{u字段{}与query{}是并行的,即query{filtered{…}scrip{u字段{…}
Ok我在elasticsearch grails插件中用一个丑陋的补丁解决了这个问题。有了这些,我也不得不改变搜索请求。我这么做是因为我只需要执行脚本_字段来计算距离。尽管我认为声明的grails插件没有利用ElasticSearch提供的完整GroovyAPI。这很难看,不是一种“非常棒”的方式,但我的时间有点短&想不出其他什么了