2015-05-01 31 views
0

我有一個名稱列和category_id列的表。以下查詢返回BadRequest錯誤。我認爲這是從錯誤blob返回的最有意義的。帶或不帶關鍵字的過濾器查詢

*備註:"something*"是我通過搜索的關鍵字。

Expected field name but got START_OBJECT 

我要尋找的查詢將返回category_id使用或不使用關鍵字搜索過濾的結果。

{ 
    query: { 
    bool: {must: [{ 
     wildcard: {name: "something*"} 
    ]}, 
    filtered: { 
     filter: { 
     bool: { 
      must: { 
      term: {category_id: 1} 
      } 
     } 
     } 
    } 
    }, 
    sort: [{ 
    _geo_distance: { 
     store_location: {:lat=>0, :lon=>0}, 
     order: "asc", 
     unit: "miles" 
    } 
    }] 
} 

這個查詢有什麼問題?

+0

mysql?不這麼認爲。 –

回答

0

如果我猜測(即未經測試),我會說這是因爲你的子查詢之外已經有了bool。把它移動到你的filtered子查詢中的query子查詢裏面如下:

{ 
    query: { 
    filtered: { 
     query: { 
     bool: {must: [{ 
      wildcard: {name: "something*"} 
     ]}, 
     }, 
     filter: { 
     bool: { 
      must: { 
      term: {category_id: 1} 
      } 
     } 
     } 
    } 
    }, 
    sort: [{ 
    _geo_distance: { 
     store_location: {:lat=>0, :lon=>0}, 
     order: "asc", 
     unit: "miles" 
    } 
    }] 
} 
+0

查詢已處理,但返回的結果爲零。我有'category_id:1'的數據,我期待。但是,此查詢不返回任何結果。 –