2012-02-01 121 views
5

如何在ElasticSearch中對子對象字段進行過濾搜索?例如,我的文檔有一個iddata領域是數據是如何存儲在我的數據庫中的JSON數組:Elasticsearch過濾搜索子對象字段

{_id: 000, merchant: "merchant_1", email: "[email protected]"}

我的搜索查詢:

"query": { 
    "filtered": { 
     "filter": { "term": { "data.merchant": "merchant_1"} }, 
     "query": { 
      "query_string": {"query": "hello"} } 
     } 
    } 
} 

沒有按」 t返回任何內容,但僅使用query_string hello執行查詢將返回正確的行。改變"data.merchant" =>"merchant"也不會改變任何東西。

我在這裏做錯了什麼?

更新:我結束了剛剛使用布爾查詢,它工作。

回答

0
"query": { 
    "filtered": { 
     "filter": { "term": { "data.merchant": "merchant_1"} }, 
     "query": { 
      "query_string": { 
       "default_field": "_all", 
       "query": "hello" 
      } 
     } 
    } 
} 

這應該適合您的情況。