Filter returns 0 hits. Why?

Hello!

Just trying to get familiar with Query DSL.

While having some index

http://localhost:9200/_search?q=status:Published

returns me all records with status field equal to Published.

And it's fine.

But when I try to repeat the example from documentation:

curl -X GET "localhost:9200/_search" -H 'Content-Type: application/json' -d'
{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "status": "Published"
        }
      }
    }
  }
}
'

it returns me 0 hits.

Can't understand why?

How can I express next URI search:

http://localhost:9200/_search?q=test AND status:Published

in Query?

Try with a match query or with published instead.

Thanks for reply!

published instead of Published works, despite its Published actually, so it looks a little bit strange to me.

The whole query I've succeeded to get to work looks now like this:

{
  "query": {
    "bool": {
      "must": {
        "query_string": {
          "query": "test"
        }
      },
      "filter": {
        "term": {
          "status": "published"
        }
      }
    }
  }
}

It's because you are using a term query and not a match query on a text field which is using the default analyzer.

Your text Published is actually indexed in the inverted index as published because of the analysis process.
The match query analyze the query the same way so Published is transformed to published which match published in the inverted index.
The term query does not analyze the query. Published does not match published but published does.

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