Find Exact same sentence from Document

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 .

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.

this is my mapping -

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

i insert 4 document /sentence -

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 -

{
    "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

Check out the match phrase query

1 Like

Thank you very much .
i've no idea how i missed about match phrase query -_- . you just save my life :smiley: :smiley: :smiley:

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