Make query case sensitive

I'm using enterprise_search and sorry I'm new to it.
I want make query case sensitive.

Like if name is Elastic then I don't want to get this doc with queryString elastic or ela

If queryString is Ela, E, stic then it is OK to match

await api
      .post(
        process.env.elasticSearchURL,
        {
          query: queryString,
          page: { size: pagination.rowsPerPage, current: pagination.page },
        },
        {
          headers: {
            Authorization: process.env.elasticSearchKey,
            'Content-Type': 'application/json',
          },
        }
      )
      .then((response) => {
})

How can I achieve it?
At present query is return case insensitive results.

I know filter is case sensitive but is it possible to do match Elastic from Elas using filter?

Hello Ankur and welcome to the Elastic community!

The short answer is, with the default settings this is not possible, but depending on your expected query patterns you can modify your query or your mapping to support your searches.

Since code is defined as a text field, the text values in this field go through analysis. The built-in analyzer splits and lowercases the terms in the field, so searching cannot be done case sensitively. This is on purpose.

If you need case sensitive search, you can try targeting your search against the code.enum field, which is a keyword subfield of code. Enterprise Search automatically creates this subfield. Keyword fields do not go through the analysis process, so the value is stored as-is (preserving case).

On keyword fields exact matching and prefix searching are supported. Suffix search is also possible ("stic" will find "Elastic"), although it's not recommended due to performance reasons - if that is a requirement, it's better to write an ngram analyzer.

Hope this helps!

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