Filter with query match_all VS

I have 2 types of requests. They are both logically identical, but I'm not sure if there is a performance difference between them.

I would be glad if someone can enlighten me.

Using match_all

and filter

:

{
  "query": {
    "filtered": {
      "query": {
        "term": {
          "user_id": "1234567"
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "range": {
                "ephoc_date": {
                  "lt": 1437033590,
                  "gte": 1437026390
                }
              }
            }
          ]
        }
      }
    }
  }
}

      


Using Query term

:

{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "user_id": "1234567"
              }
            },
            {
              "range": {
                "ephoc_date": {
                  "lt": 1437033590,
                  "gte": 1437026390
                }
              }
            }
          ]
        }
      }
    }
  }
}

      

+3


source to share


1 answer


At your request, it seems that it doesn't matter to you how documents will be evaluated based on the field value user_id

, which is "1234567". My point is that if more than one document is user_id

set to "1234567" then you don't need the order of the documents in the result. If so, the second option is better in performance because there is some estimated cost associated with scoring in the first query, while there is no scoring in the second query. By the way, your second query can also be simplified below:



{
   "filter": {
      "bool": {
         "must": [
            {
               "term": {
                  "user_id": "1234567"
               }
            },
            {
               "range": {
                  "ephoc_date": {
                     "lt": 1437033590,
                     "gte": 1437026390
                  }
               }
            }
         ]
      }
   }
}

      

+3


source







All Articles