FilteredQuery slower than query and filter?


(Juan Jose Sanchez Arroyo) #1

Hi people,

I have executed this query into production, it tooks 2 seconds:

CURL -XGET 'http://blablabla/_search?routing=061500000015181033' -d '
{
  "size": 0,
  "query": {
    "filtered": {
      "query": {
        "term": {
          "blabla": "035345353"
        }
      },
      "filter": {
        "range": {
          "fecha": {
            "from": "20130101",
            "to": "20150501",
            "include_lower": true,
            "include_upper": true
          }
        }
      }
    }
  },
  "aggs": {
    "Sectores": {
      "terms": {
        "field": "descripcionSector"
      },
      "aggs": {
        "sumaSector": {
          "sum": {
            "field": "importe"
          }
        },
        "Subsectores": {
          "terms": {
            "field": "descripcionSubsector"
          },
          "aggs": {
            "sumaSubSector": {
              "sum": {
                "field": "importe"
              }
            }
          }
        }
      }
    }
  }
}'

and this one only took 159 ms

curl -XGET 'http://blablabla/_search?routing=061500000015181033' -d '
{
  "size": 0,
  "query": {
    "term": {
      "blala": "061500000015181033"
    }
  },
  "filter": {
    "range": {
      "fecha": {
        "gte": 20130101
      }
    }
  },
  "aggs": {
    "Sectores": {
      "terms": {
        "field": "descripcionSector"
      },
      "aggs": {
        "sumaSector": {
          "sum": {
            "field": "importe"
          }
        },
        "Subsectores": {
          "terms": {
            "field": "descripcionSubsector"
          },
          "aggs": {
            "sumaSubSector": {
              "sum": {
                "field": "importe"
              }
            }
          }
        }
      }
    }
  }
}'

Server was attending same level of requests at the time of executing, no overload...so why there's so much time difference? I guess caching is involved, but I thought filteredQuery was faster...

Does anyone can help me to understand this?

Regards


(Camilo Sierra) #2

this to querys don't give you the same results, if you use filtered your aggregation and hits will be filter by (query and filter) in the second request, the hits be filter by your (filter + query) BUT the aggregatios will be use only your (query)!

@kimchy in this post explains the difference : What is the difference between filtered query and regular query with filter?


(system) #3