# Search query builder and mapping

**URL:** <https://discuss.elastic.co/t/search-query-builder-and-mapping/330715>\
**Category:** Elasticsearch\
**Created:** [April 25, 2023, 8:58am UTC](https://discuss.elastic.co/t/search-query-builder-and-mapping/330715 "2023-04-25T08:58:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SIMONE2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simone2/32/118222_2.png) [@SIMONE2](https://discuss.elastic.co/u/SIMONE2)\
**Post date:** [April 25, 2023, 8:58am UTC](https://discuss.elastic.co/t/search-query-builder-and-mapping/330715/1 "2023-04-25T08:58:25Z")

</div>

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:

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

```

con questo analyzer:

```auto
`{
    "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?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 25, 2023, 7:16pm UTC](https://discuss.elastic.co/t/search-query-builder-and-mapping/330715/2 "2023-04-25T19:16:05Z")

</div>

Hi @SIMONE2

Without much details of the purpose I might suggest the [wildcard query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html).  
Do you use this partial search to perform the autocomplete? In that case there are other options.

---

<div class="post-metadata">

**Author:** ![SIMONE2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simone2/32/118222_2.png) [@SIMONE2](https://discuss.elastic.co/u/SIMONE2)\
**Post date:** [April 26, 2023, 6:44am UTC](https://discuss.elastic.co/t/search-query-builder-and-mapping/330715/3 "2023-04-26T06:44:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 26, 2023, 11:55am UTC](https://discuss.elastic.co/t/search-query-builder-and-mapping/330715/4 "2023-04-26T11:55:11Z")

</div>

Try this:

```auto
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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 24, 2023, 11:56am UTC](https://discuss.elastic.co/t/search-query-builder-and-mapping/330715/5 "2023-05-24T11:56:10Z")

</div>

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