2016-12-01 95 views
0

當我有以下查詢:問題與彈性搜索使用嵌套查詢

{ 
    "from": 0, 
    "size": 20, 
    "sort": { 
     "prices_count": "desc" 
    }, 
    "query": { 
     "bool": { 
      "must": [{ 
       "terms": { 
        "category_ids": ["3"] 
       } 
      }, { 
       "terms": { 
        "manufacturer_id": ["5"] 
       } 
      }, { 
       "range": { 
        "prices_count": { 
         "gte": 1 
        } 
       } 
      }] 
     }, 
     "nested": { 
      "bool": { 
       "must": [{ 
        "match": { 
         "specs.model": "iphone-6s" 
        } 
       }] 
      } 
     } 
    } 
} 

我收到以下錯誤:

Fatal error: Uncaught exception 'Elastica\Exception\ResponseException' with message 'failed to parse search source. expected field name but got [START_OBJECT]' in 

如果我在查詢中只留下nested部分,它作爲預期。

是沒可能有,並在同一請求「普通」和嵌套查詢,或者我做錯了我?

回答

1

你需要把它寫這樣的:

{ 
    "from": 0, 
    "size": 20, 
    "sort": { 
    "prices_count": "desc" 
    }, 
    "query": { 
    "bool": { 
     "must": [ 
     { 
      "terms": { 
      "category_ids": [ 
       "3" 
      ] 
      } 
     }, 
     { 
      "terms": { 
      "manufacturer_id": [ 
       "5" 
      ] 
      } 
     }, 
     { 
      "range": { 
      "prices_count": { 
       "gte": 1 
      } 
      } 
     }, 
     { 
      "nested": { 
      "path": "specs", 
      "query": { 
       "match": { 
       "specs.model": "iphone-6s" 
       } 
      } 
      } 
     } 
     ] 
    } 
    } 
} 
+0

哈利路亞!謝謝! :) – galdikas

+0

真棒,很高興它幫助! – Val