# Find Exact same sentence from Document

**URL:** <https://discuss.elastic.co/t/find-exact-same-sentence-from-document/244663>\
**Category:** Elasticsearch\
**Created:** [August 12, 2020, 6:46am UTC](https://discuss.elastic.co/t/find-exact-same-sentence-from-document/244663 "2020-08-12T06:46:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aninda\_halder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aninda_halder/32/68707_2.png) [@aninda\_halder](https://discuss.elastic.co/u/aninda_halder)\
**Post date:** [August 12, 2020, 6:46am UTC](https://discuss.elastic.co/t/find-exact-same-sentence-from-document/244663/1 "2020-08-12T06:46:42Z")

</div>

Suppose i'm 3 documents .  
`Abul hassan was a actor`  
`hassan was a actor`  
`abul was a actor`

if i want to search for `abul hassan` ,search query will return all of the 3 document , but i want to get only 1st document as this document has `abul hassan` .

i want to get those document which will have exactly same sentence(multiple words) that i searched for . how would i achieve my goal .

---

<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 12, 2020, 8:56am UTC](https://discuss.elastic.co/t/find-exact-same-sentence-from-document/244663/2 "2020-08-12T08:56:35Z")

</div>

Please share reproducible examples of your queries, otherwise it is impossible to help. In this example I suppose you are running an `OR` search instead of an `AND` search and you need to specify that as part of your query.

---

<div class="post-metadata">

**Author:** ![aninda\_halder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aninda_halder/32/68707_2.png) [@aninda\_halder](https://discuss.elastic.co/u/aninda_halder)\
**Post date:** [August 13, 2020, 8:44am UTC](https://discuss.elastic.co/t/find-exact-same-sentence-from-document/244663/3 "2020-08-13T08:44:30Z")

</div>

> [@aninda\_halder](#):
>
> `abul was a actor`

this is my mapping -

```auto
{
	mappings: {
		properties: {
			transcript: {
				type: "text",
				fields: {
					keyword: {
						type: "keyword",
						ignore_above: 256
					}
				}
			}
		}
	}
}

```

i insert 4 document /sentence -

```auto
Abul hassan was a actor
hassan was a actor
abul was a actor
abul was a actor and hassan was a police

```

This is my query -

```auto
{
    "query":{
            "match": {
                "transcript":{
                    "query": "abul hassan"
                }

            }

    }
}

```

This query return all of the documents , however if i use `AND` operator it'll return  
2 documents (`Abul hassan was a actor` & `abul was a actor and hassan was a police`), but i want to get only `Abul hassan was a actor` document as only this document has `Abul hassan` in it

---

<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 13, 2020, 12:01pm UTC](https://discuss.elastic.co/t/find-exact-same-sentence-from-document/244663/4 "2020-08-13T12:01:00Z")

</div>

Check out the [match phrase query](https://www.elastic.co/guide/en/elasticsearch/reference/7.8/query-dsl-match-query-phrase.html)

---

<div class="post-metadata">

**Author:** ![aninda\_halder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aninda_halder/32/68707_2.png) [@aninda\_halder](https://discuss.elastic.co/u/aninda_halder)\
**Post date:** [August 13, 2020, 6:07pm UTC](https://discuss.elastic.co/t/find-exact-same-sentence-from-document/244663/5 "2020-08-13T18:07:26Z")

</div>

Thank you very much .  
i've no idea how i missed about [match phrase query](https://www.elastic.co/guide/en/elasticsearch/reference/7.8/query-dsl-match-query-phrase.html) -\_- . you just save my life 😃 😃 😃

---

<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 10, 2020, 6:07pm UTC](https://discuss.elastic.co/t/find-exact-same-sentence-from-document/244663/6 "2020-09-10T18:07:37Z")

</div>

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