2012-03-28 9 views

risposta

3
{ 
"query" : { 
     "filtered" : { 
     "filter" : { 
      "bool" : { 
      "must" :[{"term":{"_type":"UserAudit"}}, {"term" : {"eventType": "REGISTRATION"}}] 
      } 
     } 
     } 
    }, 
    "aggs":{ 
     "monthly":{ 
     "date_histogram":{ 
      "field":"timestamp", 
      "interval":"1y" 
     }, 
     "aggs":{ 
      "existing_visitor":{ 
       "terms":{ 
        "field":"existingGuest" 
       } 
      } 
     } 
     } 
    } 
} 

"_type": "UserAudit" condizione cercherà i record solo specifici per digitare

14

È inoltre possibile utilizzare query di dsl per filtrare i risultati per tipo specifico come questo:

$ curl -XGET 'http://localhost:9200/_search' -d '{ 
    "query": { 
     "filtered" : { 
      "filter" : { 
       "type" : { "value" : "my_type" } 
      } 
     } 
    } 
} 
' 
+2

Sconsigliata a 2.0.0-beta1. Utilizzare la query bool invece con una clausola must per la query e una clausola di filtro per il filtro. – zVictor

0

sulla versione 2.3 è possibile interrogare _type field come:

{ 
    "query": { 
    "terms": { 
     "_type": [ "type_1", "type_2" ] 
    } 
    } 
} 

O se yo u desidera escludere un tipo:

{ 
    "query": { 
    "bool" : { 
     "must_not" : { 
     "term" : { 
      "_type" : "Hassan" 
     } 
     } 
    } 
    } 
}