# ElasticSearch completion suggester without respecting terms order when typing

**URL:** https://discuss.elastic.co/t/elasticsearch-completion-suggester-without-respecting-terms-order-when-typing/193975
**Category:** Elasticsearch
**Created:** [August 6, 2019, 10:02am UTC](https://discuss.elastic.co/t/elasticsearch-completion-suggester-without-respecting-terms-order-when-typing/193975 "2019-08-06T10:02:28Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ahlem](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@ahlem](https://discuss.elastic.co/u/ahlem)
#### Post date: [August 6, 2019, 10:02am UTC](https://discuss.elastic.co/t/elasticsearch-completion-suggester-without-respecting-terms-order-when-typing/193975/1 "2019-08-06T10:02:28Z")

</div>

I wanna make an autocomplete feature to search by full name(first name(s)+ last name) using Elastic Search completion suggester.  
when tapping, user can start with any term composing the full name.  
for example to look for OUNZAIN Allel Ali, the end user could tape(order is not important ):  
ounzain allel ali, ounzain ali allel, allel ali ounzain ali allel ounzain

after reading some about completion suggester and analyzer , as a first solution I have created an index with default  
parameters (ie: simple analyzer) and a completion field, as described bellow

```auto
{
    "settings" : {
        "number_of_shards" : 5
    },
    "mappings" : {
        "_doc" : {
            "properties" : {
                "suggest_member" : { "type" : "completion"
                
                }
//... there is other fields in my index of course
         }
        }
    }
}

```

and when indexing, I have filled in the completion field with an input parameter which is  
supposed(according to my comprehension) resolve the probleme of not respecting order.  
I'll explain my solution using the above exemple: for the name: OUNZAIN Allel Ali  
the script for indexing is:

```auto
 {
"properties" : {
                "suggest_member" :{
				"input":["ouzain allel ali","ouzain ali allel", " ali ouzain allel"," ali allel ouzain",
"allel ouzain ali","allel ali ouzain"] ]
				}
}

```

the solution is to fill in the input parameters with all the possibile combinations of the couple first name(s)/last name.

I need a professional opinion about this solution, is it a good one? is there another way to implement my feature?

Many thanks for considering my request. 🙂

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [August 7, 2019, 10:31am UTC](https://discuss.elastic.co/t/elasticsearch-completion-suggester-without-respecting-terms-order-when-typing/193975/2 "2019-08-07T10:31:09Z")

</div>

this solution requires a fair share of work on your side to provide the data. If that is feasible and works out, nice. However you might also want to take a look at the new [search-as-you-type datatype](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/search-as-you-type.html), allowing you to just store the name as is.

Hope this helps.

---

<div class="post-metadata">

### Author: ![ahlem](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@ahlem](https://discuss.elastic.co/u/ahlem)
#### Post date: [August 7, 2019, 10:51am UTC](https://discuss.elastic.co/t/elasticsearch-completion-suggester-without-respecting-terms-order-when-typing/193975/3 "2019-08-07T10:51:13Z")

</div>

@spinscale, thank you for your answer, 🙂  
yes, i have already implemented this solution and it works. but I'd like to know if it's a correct one, if it will not create duplicate data when ES will create a inverse index when creating document, because in the input field I have repreted terms many times?  
I'll also take a look to search as you type field.

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [August 7, 2019, 11:04am UTC](https://discuss.elastic.co/t/elasticsearch-completion-suggester-without-respecting-terms-order-when-typing/193975/4 "2019-08-07T11:04:05Z")

</div>

the completion suggester stores its data in another data structure than the inverted index, that is also loaded into the heap permanently, so there will be differences in its runtime requirements.

---

<div class="post-metadata">

### Author: ![ahlem](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@ahlem](https://discuss.elastic.co/u/ahlem)
#### Post date: [August 7, 2019, 11:07am UTC](https://discuss.elastic.co/t/elasticsearch-completion-suggester-without-respecting-terms-order-when-typing/193975/5 "2019-08-07T11:07:16Z")

</div>

@spinscale, here is a screenshot of my autocomplete feature

 ![Screenshot_20190807-115751%5B1%5D](https://us1.discourse-cdn.com/elastic/original/3X/6/7/67f5103ce58d2924aacca7eca63147691fa32ddc.png) ![Screenshot_20190807-115729%5B1%5D](https://us1.discourse-cdn.com/elastic/original/3X/0/7/07bb1ed779b1f77027139025e482ee8a716e69f7.png)

no matter the order of terms the engine retreive the same element (document)

---

<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: [September 4, 2019, 11:07am UTC](https://discuss.elastic.co/t/elasticsearch-completion-suggester-without-respecting-terms-order-when-typing/193975/6 "2019-09-04T11:07:21Z")

</div>

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