Search query builder and mapping

Hello everyone,

I inherited the mapping of a service (JAVA SPRING BOOT)with Elasticsearch and I'm going crazy for the search.

my field is so mapped:

"organizationNames":{
         "type":"text",
         "fields":{
            "original":{
               "type":"keyword"
            }
         },
         "fielddata":true,
         "copy_to":"text",
         "analyzer":"k_analyzer"
      }`

con questo analyzer:

`{
    "analysis": {
      "analyzer": {
        "k_analyzer": {
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "stop",
            "classic",
            "stemmer",
            "kstem"
          ]
        }
      }
    }
}`

with innerBool.should(QueryBuilders. ........),
I can't make the exact match: if I have energy and green energy
if I search for "energy" both come up, how can I map my field in such a way that if I search for "eng" both come up and if I search for "energy" only energy comes out?

Hi @SIMONE2

Without much details of the purpose I might suggest the wildcard query.
Do you use this partial search to perform the autocomplete? In that case there are other options.

HI
I tried with the wildcard *energy*

but so I get 2 records, energy and blue energy, I want that if I write energy, only energy comes out.
I can't find a valid option, do you know any?

Try this:

POST your_index/_doc
{"organizationNames":"green energy"}

POST your_index/_doc
{"organizationNames":"energy"}

GET your_index/_search
{
  "query": {
    "wildcard": {
      "organizationNames.keyword": {
        "value": "ener*"
      }
    }
  }
}

Keep in mind that wildcards can experience performance degradations.

Avoid beginning patterns with * or ?. This can increase the iterations needed to find matching terms and slow search performance.