Jim G.
Jim G.

Reputation: 15363

Query-Term and Filter-Term Return Zero Results on an Exact Match, but Query-Match Returns a Result. Why?

Given:

But of these three, only the third one returned a result.

Why is this? Shouldn't they all have returned a result?

Upvotes: 1

Views: 848

Answers (2)

BasK
BasK

Reputation: 292

If u are not used an analyzer means elastic search term query and term query Filter should not support the Upper case Value. Please use "foo" in Your Query. please use this way

curl -XGET localhost:9200/index/incident/_search -d '{
"query":{
"term":{"field1":{"value":"value1"}
}}}'

but match all query is support upper and lower case. Hope it will work.

Upvotes: 0

Andrei Stefan
Andrei Stefan

Reputation: 52368

By default, using the standard analyzer, ES places your "Foo" in an index as "foo" (meaning, lowercased). When searching for term, ES doesn't use an analyzer so, it is actually searching for "Foo" (exact case). Whereas, in its index the "foo" exists (because of the analyzer).

The value passed for match instead is analyzed and ES is actually searching for "foo" in its indices, not "Foo" as it does with term.

So, the behavior you see is normal and this is how it's supposed to work. Here about match:

A family of match queries that accept text/numerics/dates, analyzes it, and constructs a query out of it.

Here about term:

Matches documents that have fields that contain a term (not analyzed).

Upvotes: 2

Related Questions