# Search term position

**URL:** <https://discuss.elastic.co/t/search-term-position/226514>\
**Category:** Elasticsearch\
**Created:** [April 4, 2020, 1:10pm UTC](https://discuss.elastic.co/t/search-term-position/226514 "2020-04-04T13:10:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luan\_Pereira](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luan_pereira/32/65660_2.png) [@Luan\_Pereira](https://discuss.elastic.co/u/Luan_Pereira)\
**Post date:** [April 4, 2020, 1:10pm UTC](https://discuss.elastic.co/t/search-term-position/226514/1 "2020-04-04T13:10:41Z")

</div>

Hi, I'm using version 6.8.

How to configure the search to prioritize products that have the search term in ascending order? For example, when typing the word "oil" (cooking oil) I want the search result to prioritize products that have the first word searched. What is happening is that the result returns products without order that have the search term at the beginning, in the middle and at the end, attached.

This my index settings:

```auto
    {
       "number_of_shards": 1,
       "number_of_replicas": 0,
       "analysis": {
           "analyzer": {
               "std": {
                   "tokenizer": "standard",
                   "char_filter": "html_strip",
                   "filter": ["standard", "elision", "asciifolding", "lowercase", "length"]
               },
               "keyword": {
                   "tokenizer": "keyword",
                   "filter": ["asciifolding", "lowercase", "length"]
               },
               "keyword_prefix": {
                   "tokenizer": "keyword",
                   "filter": ["asciifolding", "lowercase", "edge_ngram_front"]
               },
               "text_prefix": {
                   "tokenizer": "standard",
                   "char_filter": "html_strip",
                   "filter": ["standard", "elision", "asciifolding", "lowercase", "edge_ngram_front"]
               },
               "text_suffix": {
                   "tokenizer": "standard",
                   "char_filter": "html_strip",
                   "filter": ["standard", "elision", "asciifolding", "lowercase", "edge_ngram_back"]
               }
           },
           "filter": {
               "edge_ngram_front": {
                   "type": "edgeNGram",
                   "min_gram": 1,
                   "max_gram": 20,
                   "side": "front"
               },
               "edge_ngram_back": {
                   "type": "edgeNGram",
                   "min_gram": 1,
                   "max_gram": 20,
                   "side": "back"
               },
               "length": {
                   "type": "length",
                   "min": 1,
                   "min_subword_size": 1
               }
           }
       }
    }

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 6, 2020, 3:30pm UTC](https://discuss.elastic.co/t/search-term-position/226514/2 "2020-04-06T15:30:01Z")

</div>

I think you can do that using a `bool` query with multiple queries within the `should` array.  
Then you can boost for example a `prefix` query.

---

<div class="post-metadata">

**Author:** ![Luan\_Pereira](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luan_pereira/32/65660_2.png) [@Luan\_Pereira](https://discuss.elastic.co/u/Luan_Pereira)\
**Post date:** [April 6, 2020, 5:17pm UTC](https://discuss.elastic.co/t/search-term-position/226514/3 "2020-04-06T17:17:46Z")

</div>

Hi @dadoonet How i do it on index settings?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 6, 2020, 5:56pm UTC](https://discuss.elastic.co/t/search-term-position/226514/4 "2020-04-06T17:56:43Z")

</div>

You can't I think.

---

<div class="post-metadata">

**Author:** ![Luan\_Pereira](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luan_pereira/32/65660_2.png) [@Luan\_Pereira](https://discuss.elastic.co/u/Luan_Pereira)\
**Post date:** [April 6, 2020, 8:14pm UTC](https://discuss.elastic.co/t/search-term-position/226514/5 "2020-04-06T20:14:23Z")

</div>

Thanks for listening, but I didn't understand how I should solve this problem.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 6, 2020, 8:43pm UTC](https://discuss.elastic.co/t/search-term-position/226514/6 "2020-04-06T20:43:19Z")

</div>

Is there something I should be more specific about?

> [@dadoonet](#):
>
> you can do that using a `bool` query with multiple queries within the `should` array.  
> Then you can boost for example a `prefix` query.

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![Luan\_Pereira](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luan_pereira/32/65660_2.png) [@Luan\_Pereira](https://discuss.elastic.co/u/Luan_Pereira)\
**Post date:** [April 6, 2020, 10:30pm UTC](https://discuss.elastic.co/t/search-term-position/226514/7 "2020-04-06T22:30:48Z")

</div>

Okay, I have the magento e-commerce application, which has the search module from Wyomind Elasticsearch® Autocomplete. Within this module there is an index settings configuration (the json file from the first post) where I was recommended by the module's support to solve my problem.

The scenario is as follows, when I search for a product by the term "oil", the search results are products with the name "Mobil Oil", "Soy Oil", "Oil Shampoo", "Oil Sardine", "Sunflower Oil ", "Lavender Oil Adhesive Gel " and the expected result should be "Oil Shampoo", "Oil Sardine", "Lavender Oil Adhesive Gel ", "Mobil Oil", "Soy Oil", "Sunflower Oil ", that is, in ascending order from the searched term.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 7, 2020, 12:39am UTC](https://discuss.elastic.co/t/search-term-position/226514/8 "2020-04-07T00:39:20Z")

</div>

Do you have any way to configure the query which is ran behind the scene?  
If not, could you at least share the query which is generated by the plugin?

Cc @Aurelien_FOUCRET in case he has an idea.

---

<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 5, 2020, 12:39am UTC](https://discuss.elastic.co/t/search-term-position/226514/9 "2020-05-05T00:39:20Z")

</div>

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