Need to implement a if then do this kind of query on elastic search


(Shashank Paliwal) #1

I have an elastic search structure like below

    {
  "_source": {
    "@timestamp": "2017-12-08T16:31:27.106Z",
    "@version": "1",
    "doc": {
      "core": {
        "type": "admin",
        "component": {
          "items": {}
        }
      }
    }
  },
  "sort": [
    1512641620092
  ]
}

Here the value of type may change, like "advisor" etc, I need a query to fetch all types but for admin all the data where the "component.items" is not blank

SO the result should contain all types + (admin with component.type not blank )

I am new to elastic search please help here.

Thanks in advance for any help


(Adrien Grand) #2
{
  "query": {
    "bool": {
      "should": [
        { "exists": { "field": "doc.core.component.items" } },
        { "bool": { "must": { "match_all": {} },  "must_not": { "match": { "doc.core.type": "admin" } } } }
      ]
    }
  }
}

(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.