elasticsearch term query doesn't work elasticsearch term query doesn't work elasticsearch elasticsearch

elasticsearch term query doesn't work


The term query looks for the exact term. Is likely that you are using the standard analyzer which has the lowercase filter. So you are searching for exactly "Term1" when what is in the index is "term1".

Term is great for things like exact match numbers or ids (like 9844-9332-22333). Less so for a fields like titles of posts.

To confirm this you could do:

{    "query": {       "term": {            "title.keyword":"Test1"        }    }}

Which should work if your record is indexed with the exact title of "Test1". This uses the keyword analyzer instead of the standard analyzer (notice the ".keyword" after title). In the latest versions of elasticsearch the keyword analyzer is added by default unless you override this behavior. Keyword is an exact match "noop" analyzer that returns the entire string as a single token to match against.

For a title, what you probably want is:

{    "query": {       "match": {            "title":"Test1"        }    }}

Match query runs your input string through the standard analyzer that was used by default to index the document (lowercaseing etc) so elasticsearch is able to match your query text to what is in the elasticsearch index.

Checkout the docs for more details on match vs term.https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.htmlhttps://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html