Vishal
Vishal

Reputation: 91

NEST elasticsearch -C# - Case sensitive Search

We are new to elastic search and NEST.

We are trying to do case sensitive search using C# client - NEST. We have read lots of posts but could not figure out it. Can someone please us with detail step by step instructions.

Any help will be highly appreciated.

Thanks, VB.

Upvotes: 2

Views: 3240

Answers (2)

AggieEric
AggieEric

Reputation: 1209

I know this is an older question, but I ran across it in my research. So, here's my answer.

First, switching to a TERM query did not help. Upon learning more about how ElasticSearch works by default, I understand why.

By default, ElasticSearch is case-insensitive. When documents are indexed, the default analyzer lowercases all of the string values and keeps the lowercase values for future searches. This does not affect the values stored in the documents themselves, but the lowercasing does affect searches.

If you are using the default analyzer, then your search terms for string values should be all lowercase.

Before I learned how this worked, I spent a fair amount of time looking at a mixed-case field value in an indexed document, then searching with a query term that used the same mixed-case value. Zero results. It wasn't until I forced the value my query used to all lowercase that I started getting results.

You can read more about ElasticSearch analyzers here: ElasticSearch - Analysis

Upvotes: 6

Przemysław Kalita
Przemysław Kalita

Reputation: 2017

Try TERM query, are values passed to TERM query are not analyzed, thus ES is not making lower case of your input.

Here: http://www.elasticsearch.org/guide/reference/query-dsl/term-query/

Upvotes: 0

Related Questions