簡體   English   中英

elasticsearch導軌排序錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM