2017-08-10 63 views
1

我們在我的公司將Elasticsearch 1.7升級到5.5。Es 5.5.1 [size]查詢格式不正確,查詢名稱後沒有start_object

總是有這樣的例外:

{"error":{"root_cause":[{"type":"parsing_exception","reason":"[size] 
query malformed, no start_object after query name","line":1,"col":355}],"type":"parsing_exception","reason":" 
[field_sort] failed to parse field [nested_filter]","line":1,"col":355,"caused_by": 
{"type":"parsing_exception","reason":"Expected nested_filter element.","line":1,"col":355,"caused_by": 
{"type":"parsing_exception","reason":"[size] query malformed, no start_object after query 
name","line":1,"col":355}}},"status":400} 

查詢:

{ 
    "from": 0, 
    "size": 48, 
    "query": { 
     "bool": { 
     "must": null, 
     "filter": { 
      "bool": { 
       "must": [ 
        { 
        "term": { 
         "published_countries.raw": "FR" 
        } 
        }, 
        { 
        "nested": { 
         "path": "categories", 
         "query": { 
          "term": { 
           "categories.slug.raw": "engrais/engrais-complexes" 
          } 
         } 
        } 
        } 
       ] 
      } 
     } 
     } 
    }, 
    "sort": [ 
     { 
     "isProductRunOut": { 
      "order": "asc" 
     } 
     }, 
     { 
     "is_featured": { 
      "order": "desc" 
     } 
     }, 
     { 
     "total_va": { 
      "order": "desc", 
      "nested_filter": { 
       "size": 12 
      } 
     } 
     }, 
     { 
     "createdAt": { 
      "order": "desc" 
     } 
     } 
    ], 
    "aggs": { 
     "top_12_total_va": { 
     "top_hits": { 
      "sort": { 
       "total_va": { 
        "order": "desc" 
       } 
      }, 
      "size": 12 
     } 
     } 
    } 
} 

我知道這個問題從nested_filter下的大小來是因爲當我刪除放入系統線路,也沒有更多的問題(事實上,我有另一個)。但我不知道如何通過這個問題。

我在symfony項目上使用Elasticsearch php客戶端。

編輯:

THX瓦爾,我忘了加上nested_pa​​th在DOC表示,第三排序等。所以它看起來像這樣:

 { 
      "total_va": { 
       "order": "desc", 
       "nested_path": "variants", 
       "nested_filter": { 
        "size": 12 
       } 
      } 
     } 

但我仍然有例外。

+0

的問題是與你的第三個'sort'約束,你在裏面有'nested_filter'沒有任何'nested_pa​​th' ......看到這:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#_nested_sorting_example – Val

+0

謝謝。我忘了添加nested_pa​​th。但我仍然有同樣的例外。 –

回答

0

找到解決方案。 我不得不更換該行:

"size": 12 

通過

"term": {"size": 12}