2017-02-17 54 views
0
存在于不同的指数

我有以下查询查询基于在Elasticsearch

{ 
    "from":0, 
    "size":50000, 
    "_source":[ 
     "T121", 
     "timestamp" 
    ], 
    "sort":{ 
     "timestamp":{ 
     "order":"asc" 
     } 
    }, 
    "query":{ 
     "bool":{ 
     "must":{ 
      "range":{ 
       "timestamp":{ 
        "gte":"2017-01-17 11:44:41.347", 
        "lte":"2017-02-18 11:44:47.878" 
       } 
      } 
     }, 
     "must":{ 
      "exists":{ 
       "field":"T121" 
      } 
     } 
     } 
    } 
} 

http://172.22.23.169:9200/index1,index2,Index3/_search?pretty

有了这个网址我要查询过一些在Elasticsearch指数和只返回这些领域其中特定领域存在的文件。

如果在其中一个文档中存在“field1”或“field2”或“fiedl3”的情况下,我可以在“exists”子句中定义 ,否则不要,或者我有脚本这样的情况?

回答

1

要搜索在所有指数使用>http://172.22.23.169:9200/_search?pretty

要跨选定索引搜索添加以下过滤器“布尔”过滤

"must": { 
    "terms": { 
    "_index": [ 
     "index1", 
     "index2" 
    ] 
    } 
} 

对于多中用OR“存在”,你可以用should条款有多个存在,并控制搜索记录指定“minimum_should_match”。

{ 
    "from":0, 
    "size":50000, 
    "_source":[ 
    "T121", 
    "timestamp" 
    ], 
    "sort":{ 
    "timestamp":{ 
     "order":"asc" 
    } 
    }, 
    "query":{ 
    "bool":{ 
     "must":{ 
     "range":{ 
      "timestamp":{ 
      "gte":"2017-01-17 11:44:41.347", 
      "lte":"2017-02-18 11:44:47.878" 
      } 
     } 
     }, 
     "should":[ 
     { 
      "exists":{ 
      "field":"field1" 
      } 
     }, 
     { 
      "exists":{ 
      "field":"field2" 
      } 
     }, 
     { 
      "exists":{ 
      "field":"field3" 
      } 
     } 
     ] 
    } 
    } 
} 
+0

非常感谢,我会试试看! –