php - Elasticsearch multiple queries -


i distinct ip's example today , campaigne="2" in sql: select distinct ip test timestamp >= "2016-01-16" ... , fk_campaign_id = "2";

this works json validator outputs "duplicate key, names should unique."

{      "size":0,    "aggs":{         "distinct_ip":{            "cardinality":{               "field":"ip"          }       }    },    "query":{         "range":{            "timestamp":{               "gte":"2016-01-16t00:00:00",             "lt":"2016-01-17t00:00:00"          }       }    },    "query":{         "match":{            "fk_campaign_id":"2"       }    } } 

but if try build query in php, var_dump($params) returns me json 1 "query", may because of duplicate key???

{      "size":0,    "aggs":{         "distinct_ip":{            "cardinality":{               "field":"ip"          }       }    }, 

part range not here?!?!?

   "query":{         "match":{            "fk_campaign_id":"2"       }    } } 

thanks in advance.

in json query duplicate key. need use bool query whenever have multiple conditions. since have and condition need use must clause. right syntax

{   "query": {     "bool": {       "must": [         {           "range": {             "timestamp": {               "gte": "2016-01-16t00:00:00",               "lt": "2016-01-17t00:00:00"             }           }         },         {           "match": {             "fk_campaign_id": "2"           }         }       ]     }   },   "size": 0,   "aggs": {     "distinct_ip": {       "cardinality": {         "field": "ip"       }     }   } } 

hope helps!


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -