2012-02-01 131 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" 
      } 
     } 
    } 
} 

这应该适合您的情况。