2014-11-21 90 views
0

我想通過索引 - >按索引類型 - >文本搜索數據按順序在ES上搜索數據。
當我在「_index」上使用下面的查詢時,我希望得到該特定_index下的index_types列表以及相關數據,但它什麼也沒有返回。另一方面,當我用_type搜索時,我得到了有關index_type的數據。我哪裏錯了?
Elasticsearch方面:在_index上搜索沒有返回結果

curl -XGET 'http://localhost:9200/_all/_search?pretty' -d '{ 
     "facets": { 
     "terms": { 
      "terms": { 
      "field": "_index", 
      "size": 10, 
      "order": "count", 
      "exclude": [] 
      }, 
      "facet_filter": { 
      "fquery": { 
       "query": { 
       "filtered": { 
        "query": { 
        "bool": { 
         "should": [ 
         { 
          "query_string": { 
          "query": "*" 
          } 
         } 
         ] 
        } 
        }, 
        "filter": { 
        "bool": { 
         "must": [ 
         { 
          "terms": { 
          "_index": [ 
           "<index_name>" 
          ] 
          } 
         } 
         ] 
        } 
        } 
       } 
       } 
      } 
      } 
     } 
     }, 
     "size": 0 
    }' 

注:我首先面臨這一問題上Kibana,其中I中使用的過濾器 「_index」: 「name_of_index」;它沒有返回結果,但「_type」:「name_of_index_type」返回了預期的結果。我發現Kibana在後臺使用上面的查詢來獲得我試過的過濾器的結果。

+0

爲什麼你不指定你的索引在url? 使用「aggs」(聚合),因爲方面折舊。 – AlainIb 2014-11-21 12:49:09

回答

0

這是一個使用前置過濾器(「query」:「*」)進行查詢的示例,然後必須執行查詢。那麼resutlt被用來做聚合:

curl -XGET 'http://localhost:9200/YOUR_INDEX_NAME/_search?size=10' -d '{ 
    "query" : { 
     "filtered" : { 
      "query" : { 
       "query_string" : { 
        "query" : "*" 
       } 
      }, 
      "filter" : { 
       "bool" : { 
        "must" : [ 
         { "term" : { "E_RECORDEDBY" : "malençon, g."} }, 
         { "term" : { "T_SCIENTIFICNAME" : "peniophora incarnata" } } 
        ], 
        "must_not" : [ 
        {"term" : { "L_CONTINENT" : "africa" } }, 
        {"term" : { "L_CONTINENT" : "europe" } } 
        ] 
      } 
      } 
     } 
    }, 
    "aggs" : { 
     "L_CONTINENT" : { 
      "terms" : { 
       "field" : "L_CONTINENT", 
       "size" : 20 
      } 
     } 
    }, 
    "sort" : "_score" 
}'