[英]elasticsearch rails sort error
我在使用Elasticsearch排序时出错。
参考资料:
http://www.elasticsearch.org/guide/zh-CN/elasticsearch/reference/current/query-dsl-match-query.html http://www.elasticsearch.org/guide/zh-CN/elasticsearch/reference/current/search -request-sort.html
我正在使用带有rails的elasticsearch-model。 以下代码段未排序并给我错误。
Ad.search(query: {
sort: [{posted_on: {order: "asc"}},
],
match: {
description: {
query: params[:search]
}
}
})
从终端尝试时,以下是错误。
curl -XPOST 'localhost:9200/_search' -d '{
"query": {
"match": {
"description": {
"query": "good center location"
}
},
"sort": [
"_score"
]
}
}'
响应是:
{
"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[eF0LAz1gQxOXKPlYGjj9eA][.marvel-2014.06.07][0]: SearchParseException[[.marvel-2014.06.07][0]: query[block.2.description:good block.2.description:center block.2.description:location],from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\" : {\n \"match\" : {\n \"description\" : {\n \"query\" : \"good center location\"\n }\n },\n \"sort\" : [\"_score\"]\n }]]]; nested: ElasticsearchParseException[Expected field name but got START_ARRAY \"sort\"]; }{[eF0LAz1gQxOXKPlYGjj9eA][.marvel-2014.05.29][0]: SearchParseException[[.marvel-2014.05.29][0]: query[block.2.description:good block.2.description:center block.2.description:location],from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\" : {\n \"match\" : {\n \"description\" : {\n \"query\" : \"good center location\"\n }\n },\n \"sort\" : [\"_score\"]\n }]]]; nested: ElasticsearchParseException[Expected field name but got START_ARRAY \"sort\"]; }{[eF0LAz1gQxOXKPlYGjj9eA][.marvel-2014.05.31][0]: SearchParseException[[.marvel-2014.05.31][0]: query[block.2.description:good block.2.description:center block.2.description:location],from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\" : {\n \"match\" : {\n \"description\" : {\n \"query\" : \"good center location\"\n }\n },\n \"sort\" : [\"_score\"]\n }]]]; nested: ElasticsearchParseException[Expected field name but got START_ARRAY \"sort\"]; }{[eF0LAz1gQxOXKPlYGjj9]}"
}
最直接而没有深入研究,它看起来像是无效的json(在此处检查: http : //jsonlint.com/ )
您发布的内容看起来像
{
"query": {
"match": {
"description": {
"query": "good center location"
}
},
"sort": [
"_score"
]
}
鉴于
{
"query": {
"match": {
"description": {
"query": "good center location"
}
},
"sort": [
"_score"
]
}
}
将是有效的
另一个问题是排序不是查询的子查询。 查看他们的用法示例,您可以看到它没有嵌套 (来源) 。
此外,score是默认排序方式,因此实际上不需要参数
在Elasticsearch中,相关性得分由搜索结果中返回的浮点数表示为_score,因此默认排序顺序为:_score降序。
诸如Marvel之类的东西(开发期间免费)将有助于防止此类错误,因为它会检查传入的json
(红色框表示错误)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.