# The search for full words or terms does not work correctly

**URL:** <https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527>\
**Category:** Elasticsearch\
**Created:** [July 22, 2024, 7:56am UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527 "2024-07-22T07:56:29Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rainbow\_Sprinkles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rainbow_sprinkles/32/121963_2.png) [@Rainbow\_Sprinkles](https://discuss.elastic.co/u/Rainbow_Sprinkles)\
**Post date:** [July 22, 2024, 7:56am UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527/1 "2024-07-22T07:56:30Z")

</div>

Dear talents,  
I hope everyone is doing well. Could you kindly review the statement below and suggest possible fixes?  
The keyword is "alt legal".  
Currently, the search engine is expected to display titles that either contain the full phrase "alt legal" or both the words "alt" and "legal". As a result, the entry "bluh bluh Alt legal" should be ranked at the top. However, the current top candidate is "LegalType," which includes "alT" and "Legal," but they are not a complete word.  
Does someone have experience like this?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 22, 2024, 9:27am UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527/2 "2024-07-22T09:27:26Z")

</div>

What is the mapping of the fields you are querying?

---

<div class="post-metadata">

**Author:** ![Rainbow\_Sprinkles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rainbow_sprinkles/32/121963_2.png) [@Rainbow\_Sprinkles](https://discuss.elastic.co/u/Rainbow_Sprinkles)\
**Post date:** [July 22, 2024, 10:12am UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527/3 "2024-07-22T10:12:45Z")

</div>

Thanks for your reply @Christian_Dahlqvist

Both of they are string type.  
I replaced displayName with title for more comprehension.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 22, 2024, 10:49am UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527/4 "2024-07-22T10:49:08Z")

</div>

What is the mapping of the fields in the index as shown using the [get mapping API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html)?

---

<div class="post-metadata">

**Author:** ![Rainbow\_Sprinkles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rainbow_sprinkles/32/121963_2.png) [@Rainbow\_Sprinkles](https://discuss.elastic.co/u/Rainbow_Sprinkles)\
**Post date:** [July 22, 2024, 12:54pm UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527/5 "2024-07-22T12:54:47Z")

</div>

Here is mapping data:

```auto
"description" : {
          "type" : "text",
          "analyzer" : "full",
          "search_analyzer" : "full_search"
        },
        "displayName" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" : "keyword"
            }
          },
          "analyzer" : "full",
          "search_analyzer" : "full_search"
        },

```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 22, 2024, 12:58pm UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527/6 "2024-07-22T12:58:11Z")

</div>

What is the definition of the `"full_search"` and `"full"` analysers? Why do you have a separate search analyser that is different from the index analyser?

---

<div class="post-metadata">

**Author:** ![Rainbow\_Sprinkles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rainbow_sprinkles/32/121963_2.png) [@Rainbow\_Sprinkles](https://discuss.elastic.co/u/Rainbow_Sprinkles)\
**Post date:** [July 22, 2024, 1:07pm UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527/7 "2024-07-22T13:07:26Z")

</div>

Well, would this be an interruption of searching for "alt legal"?  
Actually, I am a newbie on this search engine 😞

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 22, 2024, 1:33pm UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527/8 "2024-07-22T13:33:25Z")

</div>

It is key to how the search is executed, so you need to provide this information.

---

<div class="post-metadata">

**Author:** ![Rainbow\_Sprinkles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rainbow_sprinkles/32/121963_2.png) [@Rainbow\_Sprinkles](https://discuss.elastic.co/u/Rainbow_Sprinkles)\
**Post date:** [July 22, 2024, 2:58pm UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527/9 "2024-07-22T14:58:03Z")

</div>

Here is detail.

```auto
"analyzer": {
        "full": {
          "tokenizer": "full",
          "filter": [
            "lowercase",
            "asciifolding",
            "english_stop",
            "synonym"
          ],
          "char_filter": [
            "html_strip"
          ]
        },
        "full_search": {
          "tokenizer": "search",
          "filter": [
            "lowercase",
            "asciifolding",
            "english_stop",
            "synonym"
          ],
          "char_filter": [
            "html_strip"
          ]
        },
}

```

---

<div class="post-metadata">

**Author:** ![Rainbow\_Sprinkles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rainbow_sprinkles/32/121963_2.png) [@Rainbow\_Sprinkles](https://discuss.elastic.co/u/Rainbow_Sprinkles)\
**Post date:** [July 22, 2024, 4:20pm UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527/10 "2024-07-22T16:20:52Z")

</div>

Could you please take a look?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 22, 2024, 5:40pm UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527/11 "2024-07-22T17:40:59Z")

</div>

What is the definition of your synonym filter?

---

<div class="post-metadata">

**Author:** ![Rainbow\_Sprinkles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rainbow_sprinkles/32/121963_2.png) [@Rainbow\_Sprinkles](https://discuss.elastic.co/u/Rainbow_Sprinkles)\
**Post date:** [July 22, 2024, 6:00pm UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527/12 "2024-07-22T18:00:30Z")

</div>

I think there is no synonym of it in this list

---

<div class="post-metadata">

**Author:** ![Rainbow\_Sprinkles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rainbow_sprinkles/32/121963_2.png) [@Rainbow\_Sprinkles](https://discuss.elastic.co/u/Rainbow_Sprinkles)\
**Post date:** [July 22, 2024, 7:06pm UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527/13 "2024-07-22T19:06:04Z")

</div>

Actually, there is no data that is related to "legaltrek"  
Why does this issue happen?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 23, 2024, 8:39am UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527/14 "2024-07-23T08:39:43Z")

</div>

I have not had time to recreate this so would recommend that you use the [analyze API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-analyze.html) to analyze and commpare how the search string and indexed matching data are analyzed.

---

<div class="post-metadata">

**Author:** ![michaelcizmar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michaelcizmar/32/45942_2.png) [@michaelcizmar](https://discuss.elastic.co/u/michaelcizmar)\
**Post date:** [July 27, 2024, 11:59am UTC](https://discuss.elastic.co/t/the-search-for-full-words-or-terms-does-not-work-correctly/363527/15 "2024-07-27T11:59:35Z")

</div>

> [@Rainbow\_Sprinkles](#):
>
> LegalType

A couple of notes here. First, you should be aware that if you use a synonym filter last then the synonyms you place in your list will not be filtered. So those synonyms need to be in the final form.

Second, what are search and full tokenizers? There's probably no need for all of these customizations. You should start with out of the box and then make adjustments as necessary to achieve a specific result. My assumption is that y

LegalType is likely getting ngramed. So it is being tokenized ["Leg", "Lega", "Legal", "LegalT", "LegalTy","LegalTyp","LegalType","egalType","galType","alType", "lType","Type", "ype"...."alT"] (note this is not the complete list)

after tokenization you have a token "alT" and "Legal" which are then lowercased. See this: [N-gram tokenizer | Elasticsearch Guide [8.14] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-ngram-tokenizer.html)

But as Christian mentioned, use the analyze api to see how your analyzers are actually performing and you'll see the issue.
