# How to extract relevant tags from docs?

**URL:** <https://discuss.elastic.co/t/how-to-extract-relevant-tags-from-docs/50118>\
**Category:** Elasticsearch\
**Created:** [May 16, 2016, 1:03pm UTC](https://discuss.elastic.co/t/how-to-extract-relevant-tags-from-docs/50118 "2016-05-16T13:03:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bibi8](https://avatars.discourse-cdn.com/v4/letter/b/91b2a8/32.png) [@bibi8](https://discuss.elastic.co/u/bibi8)\
**Post date:** [May 16, 2016, 1:03pm UTC](https://discuss.elastic.co/t/how-to-extract-relevant-tags-from-docs/50118/1 "2016-05-16T13:03:07Z")

</div>

Hi everyone,

First, sorry for my english.

To ask my question i will expose to you an example.

I have a type tags who contains list of tags :

```auto
"_source": {
    "name": "tablet-sony",
}
"_source": {
    "name": "tv-sony"
 }
"_source": {
     "name": "tablet-samsung"
}

```

Now I want to get tags from this query :

```auto
"query": "I have tv sony and tablet samsung",

```

And I want to extract only tags : "tv-sony" and "tablet-samsung" but not "tablet-sony"

What is the best way to make this condition ?

Thank's for your help.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [May 16, 2016, 1:17pm UTC](https://discuss.elastic.co/t/how-to-extract-relevant-tags-from-docs/50118/2 "2016-05-16T13:17:38Z")

</div>

You can totally use a `bool` query with two `should` clauses, one for `"match": {"name":tv sony"}` and one for `"match": {"name": "tabled samsung"}` but I don't know of anything offhand that does the natural language parsing to figure out that that English sentence is actually two queries.

---

<div class="post-metadata">

**Author:** ![bibi8](https://avatars.discourse-cdn.com/v4/letter/b/91b2a8/32.png) [@bibi8](https://discuss.elastic.co/u/bibi8)\
**Post date:** [May 16, 2016, 3:24pm UTC](https://discuss.elastic.co/t/how-to-extract-relevant-tags-from-docs/50118/3 "2016-05-16T15:24:37Z")

</div>

Thank's for your help.

But I want a more generic query. Maybe by defined a score of each tags where the score is the distance between two words.  
Here, the score of "tablet samsung" is better than "tablet-sony" because is more clothes.

It's possible to do something like that ?

Thank's again to your help.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [May 16, 2016, 3:45pm UTC](https://discuss.elastic.co/t/how-to-extract-relevant-tags-from-docs/50118/4 "2016-05-16T15:45:48Z")

</div>

> [@bibi8](#):
>
> It's possible to do something like that ?

I don't know something already written but if you are very adventurous you could implement a plugin to add a new query type. Have a look at [match query](https://github.com/elastic/elasticsearch/blob/b8b5dc1cbad8ffde1ea6b7bfea5e176d01e8a286/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java). In particular what you are looking for is sort of like the phrase flavor of the match query but not quite because not all of the terms in the phrase have to be found.

---

<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:** [July 5, 2017, 10:51pm UTC](https://discuss.elastic.co/t/how-to-extract-relevant-tags-from-docs/50118/5 "2017-07-05T22:51:20Z")

</div>


