简体   繁体   English

elasticsearch导轨排序错误

[英]elasticsearch rails sort error

I am getting error with elasticsearch sort. 我在使用Elasticsearch排序时出错。

references: 参考资料:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html 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

I am using elasticsearch-model with rails. 我正在使用带有rails的elasticsearch-model。 The following snippet was not sorting and giving me error. 以下代码段未排序并给我错误。

Ad.search(query: {
    sort: [{posted_on: {order: "asc"}},
      ],
    match: {
      description: {
        query: params[:search]
      }
    }
  })

The following is error when trying from terminal. 从终端尝试时,以下是错误。

curl -XPOST 'localhost:9200/_search' -d '{
  "query": {
    "match": {
      "description": {
        "query": "good center location"
      }
    },
    "sort": [
      "_score"
    ]
  }
}'

response is: 响应是:

{
  "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]}"
}

Most immediately without looking at it deeply, it looks like this is not valid json (checked here: http://jsonlint.com/ ) 最直接而没有深入研究,它看起来像是无效的json(在此处检查: http : //jsonlint.com/

What you posted would look like 您发布的内容看起来像

{
    "query": {
        "match": {
            "description": {
                "query": "good center location"
            }
        },
        "sort": [
            "_score"
        ]
     }

Whereas 鉴于

{
    "query": {
        "match": {
            "description": {
                "query": "good center location"
            }
        },
        "sort": [
            "_score"
        ]
    }
}

would be valid 将是有效的

Another issue is that sort is not a sub query of query. 另一个问题是排序不是查询的子查询。 Looking at their usage example you can see that it is not nested 查看他们的用法示例,您可以看到它没有嵌套 在此处输入图片说明 (Source) . (来源)

In addition score is the default sort so that parameter is not really necessary 此外,score是默认排序方式,因此实际上不需要参数

In Elasticsearch the relevance score is represented by the floating point number returned in the search results as the _score, so the default sort order is: _score descending. 在Elasticsearch中,相关性得分由搜索结果中返回的浮点数表示为_score,因此默认排序顺序为:_score降序。

Source 资源

Something like Marvel (free during development) would help prevent these kind of errors as it checks the json being passed in 诸如Marvel之类的东西(开发期间免费)将有助于防止此类错误,因为它会检查传入的json
支票
(red box signifies an error) (红色框表示错误)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM