2015-06-17 119 views
3

ElasticSearch返回我「嘗試使用以下查詢查找條目時,沒有爲[likes_count]」錯誤註冊的查詢。該字段likes_count是一個新的文檔字段,並不存在於每個文檔中。ElasticSearch-「沒有查詢註冊...」

相同的查詢沒有排序部分。

爲什麼會出現此錯誤?

感謝

{ 
    "query": { 
    "filtered": { 
     "query": { 
     "query_string": { 
      "fields": ["description"], 
      "query": "sun" 
     }, 
     "sort": [{ 
      "likes_count": { 
      "unmapped_type": "boolean", 
      "order": "desc", 
      "missing": "_last" 
      } 
     }] 
     }, 
     "filter": {"term": {"permissions": 1}} 
    } 
    } 
} 

回答

2

撰寫您這樣的查詢,即sort需要到頂層,而不是嵌套在query部分:

{ 
    "query": { 
    "filtered": { 
     "query": { 
     "query_string": { 
      "fields": [ 
      "description" 
      ], 
      "query": "sun" 
     } 
     }, 
     "filter": { 
     "term": { 
      "permissions": 1 
     } 
     } 
    } 
    }, 
    "sort": [ 
    { 
     "likes_count": { 
     "unmapped_type": "boolean", 
     "order": "desc", 
     "missing": "_last" 
     } 
    } 
    ] 
}