1

I created an elastic search index and the result of a simple search looks like:

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 11,
    "max_score": 1,
    "hits": [
      {
        "_index": "shop-bestellung",
        "_type": "bestellung",
        "_id": "dc144b04-8e73-4ea5-9f73-95c01768fd26",
        "_score": 1,
        "_source": {
          "id": "dc144b04-8e73-4ea5-9f73-95c01768fd26",
          "bestellnummer": "B-20170302-026",
          "shopid": "0143d767-8986-432a-a15d-00e1c4862b24",
          "shopname": "DeeDa",
          "erstelltVon": "5663bb4b-fc44-46ca-b875-a3487b588b24",
          "bestellername": "Max Mann",
          "bestelldatum": "2017-01-30T23:00:00Z",
          "bestellpositionen": []
        }
      }
    ]
  }
}

I tried to create a filter which should consits of following three restrictions:

  • Query text
  • Date range
  • Filter on a specific field: "erstelltVon"

My filter only consits of query text and date range:

{  
   "query":{  
      "query_string":{  
         "fields":[  
            "bestellnummer",
            "bestellername",
            "bestelldatum",
            "erstelltVon",
            "bestellpositionen.artikelname",
            "bestellpositionen.artikelnummer",
            "bestellpositionen.referenznummer"
         ],
         "query":"*"
      }
   },
    "filter": {
        "range" : {
            "bestelldatum" : {
                "gte": "2017-02-04T23:00:00Z",
                "lte": "now",
                "time_zone": "+01:00"
            }
        }
    }
}

I would like to add the third filter:

"erstelltVon": "5663bb4b-fc44-46ca-b875-a3487b588b24"

How can I do that?

1 Answer 1

3

You need to use a boolean filter.

Here is how to use it:

  "filter": {
    "bool" : {
      "must": [
        // FIRST FILTER
        {
          "range" : {
            "bestelldatum" : {
              "gte": "2017-02-04T23:00:00Z",
              "lte": "now",
              "time_zone": "+01:00"
            }
          }
        },
        {
          // YOUR OTHER FILTER HERE
        }
      ]
    }

change "must" to "should" if you want to use a OR instead of an AND.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.