Filter vs query

Hi, can we use only filter without query and can we use query string with wildcard in filter. What are benefits of using only filter and using query string + filter? There is example of using only filter. Is this code ok?

query: {
          bool: {
            filter: [
              {
                term: { type: passedType },
              },
              {
                range: {
                  mag: {
                    gte: passedMag,
                  },
                },
              },
              {
                match: { place: passedLocation },
              }
            ],
          },
        },

A query participate to the score (how much the query matches the document) where a filter just "filters" the document without computing any score.

With queries, you can sort by the most relevant documents (default behavior).
With filters, you can just say that a document matches or not.

A filter can be cached. A query can not.

That sounds like a bad idea...

Be aware that wildcard queries can use an enormous amount of memory and perform very badly — just think how many terms need to be queried to match the query string "a* b* c*" .

2 Likes

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