2014-10-01 56 views
0

我有两个指标指数1索引2两者有两种类型TYPE1TYPE2与弹性搜索同名(请假设我们有它背后有效的商业理由)过滤器“_index”同样的方法,在多个索引查询弹性搜搜“_type”

我想搜索索引1 - TYPE1索引2 -type2

这里是我的查询

POST _search 
{ 
"query": { 
    "indices": { 
     "indices": ["index1","index2"],  
     "query": { 
     "filtered":{ 
     "query":{ 
     "multi_match": { 
      "query": "test", 
      "type": "cross_fields", 
      "fields": ["_all"]   
     } 

     }, 
     "filter":{ 
      "or":{ 
       "filters":[ 
        { 
        "terms":{ 
           "_index":["index1"], // how can i make this work? 
           "_type": ["type1"] 
        }      
        }, 
        { 
        "terms":{ 
           "_index":["index2"], // how can i make this work? 
           "_type": ["type2"] 
        }      
        } 
       ] 
      } 
     } 
     } 
     }, 
     "no_match_query":"none" 
    } 
    } 
} 
+0

你能解释一下你面临的问题吗?你的查询对我来说工作正常,我有相同的场景多个相同类型的索引。 – Roopendra 2014-10-01 04:54:46

+0

嗨Roopendra,当我执行上面的查询时,它返回的结果来自index1-> type2和index2-> type1,我不想要。我只需要index1-> type1和index2-> type2。我相信那是因为它不是在“_index”字段上过滤术语。希望是有道理的。非常感谢 – 2014-10-01 05:26:37

回答

5

可以使用indicestypebool过滤器类型和索引 过滤查询看起来会是在这些线路上:

POST index1,index2/_search 
{ 
    "query": { 
    "filtered": { 
     "query": { 
     "multi_match": { 
      "query": "test", 
      "type": "cross_fields", 
      "fields": [ 
      "_all" 
      ] 
     } 
     }, 
     "filter": { 
     "bool": { 
      "should": [ 
      { 
       "indices": { 
       "index": "index1", 
       "filter": { 
        "type": { 
        "value": "type1" 
        } 
       }, 
       "no_match_filter": "none" 
       } 
      }, 
      { 
       "indices": { 
       "index": "index2", 
       "filter": { 
        "type": { 
        "value": "type2" 
        } 
       }, 
       "no_match_filter": "none" 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 
} 

薪火指数url示例中的名称:index1,index2/_search是一种很好的做法,否则您有可能在集群中的所有索引上执行查询。

+0

非常感谢。索引过滤器里面的一个改进就是使用术语,所以我可以有多种类型。 **“filter”:{ “terms”:{“_type”:[“type1”,“type3”,“type5”]} } ** – 2014-10-01 22:08:06