# How can I remove duplicated keyword with the same category in ElasticSearch?

**URL:** <https://discuss.elastic.co/t/how-can-i-remove-duplicated-keyword-with-the-same-category-in-elasticsearch/125477>\
**Category:** Elasticsearch\
**Created:** [March 25, 2018, 10:42am UTC](https://discuss.elastic.co/t/how-can-i-remove-duplicated-keyword-with-the-same-category-in-elasticsearch/125477 "2018-03-25T10:42:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nutanek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nutanek1/32/29009_2.png) [@nutanek1](https://discuss.elastic.co/u/nutanek1)\
**Post date:** [March 25, 2018, 10:42am UTC](https://discuss.elastic.co/t/how-can-i-remove-duplicated-keyword-with-the-same-category-in-elasticsearch/125477/1 "2018-03-25T10:42:55Z")

</div>

I want to build completion suggester in ElasticSearch.

I have data look like this.

```
{
    "suggest": {
        "input": ["iphone", "iphone x"]
    },
    "category_id": 1 
},
{
    "suggest": {
        "input": ["iphone", "iphone 8"]
    },
    "category_id": 2
},
{
    "suggest": {
        "input": ["iphone", "iphone 7"]
    },
    "category_id": 1 
}

```

And when I search with "iphone" keyword I want it checks duplicated keywords with different category\_id.

This is result that I want to see.

```
{
    "suggest": iphone
    "category": 1
},
{
    "suggest": iphone
    "category": 2
}

```

If I use skip\_duplicates feature, it will returns me only one record because "iphone" are duplicated.

Thanks for your helps.

---

<div class="post-metadata">

**Author:** ![ddorian43](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ddorian43/32/36093_2.png) [@ddorian43](https://discuss.elastic.co/u/ddorian43)\
**Post date:** [March 25, 2018, 5:53pm UTC](https://discuss.elastic.co/t/how-can-i-remove-duplicated-keyword-with-the-same-category-in-elasticsearch/125477/2 "2018-03-25T17:53:33Z")

</div>

You can encode "category" in the name, like `["iphone:c1", "iphone 8:c1"]`

Or make 2 suggest queries for each `category_id` and merge them on the client.

---

<div class="post-metadata">

**Author:** ![nutanek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nutanek1/32/29009_2.png) [@nutanek1](https://discuss.elastic.co/u/nutanek1)\
**Post date:** [March 25, 2018, 6:35pm UTC](https://discuss.elastic.co/t/how-can-i-remove-duplicated-keyword-with-the-same-category-in-elasticsearch/125477/3 "2018-03-25T18:35:58Z")

</div>

Encoding "category id" into keyword that's a good idea! Thanks you very much^^

But if I **make 2 suggest queries for each category\_id and merge them on the client** that means I have to query 2 times, right? If I have 100 categories, I think that is not good to do this approach! or I misunderstand about this?

---

<div class="post-metadata">

**Author:** ![ddorian43](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ddorian43/32/36093_2.png) [@ddorian43](https://discuss.elastic.co/u/ddorian43)\
**Post date:** [March 25, 2018, 6:37pm UTC](https://discuss.elastic.co/t/how-can-i-remove-duplicated-keyword-with-the-same-category-in-elasticsearch/125477/4 "2018-03-25T18:37:17Z")

</div>

You can make multiple queries in 1 request but yes.

---

<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:** [April 22, 2018, 6:38pm UTC](https://discuss.elastic.co/t/how-can-i-remove-duplicated-keyword-with-the-same-category-in-elasticsearch/125477/5 "2018-04-22T18:38:14Z")

</div>

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