# Search two words in the same sentence

**URL:** https://discuss.elastic.co/t/search-two-words-in-the-same-sentence/366914
**Category:** Elastic Search
**Tags:** painless, elastic-app-search
**Created:** [September 22, 2024, 6:11am UTC](https://discuss.elastic.co/t/search-two-words-in-the-same-sentence/366914 "2024-09-22T06:11:10Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Hamed\_Barati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hamed_barati/32/137779_2.png) [@Hamed\_Barati](https://discuss.elastic.co/u/Hamed_Barati)
#### Post date: [September 22, 2024, 6:11am UTC](https://discuss.elastic.co/t/search-two-words-in-the-same-sentence/366914/1 "2024-09-22T06:11:10Z")

</div>

I have got a index that it saved articles. The articles index has got abstract and content field. I have set `text` type for abstract and content mapping.  
I wanna search two words what appear in the same sentence in abstract or content field. And also I must check the slop words between theirs.  
How do I do it?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 22, 2024, 7:02am UTC](https://discuss.elastic.co/t/search-two-words-in-the-same-sentence/366914/2 "2024-09-22T07:02:11Z")

</div>

Welcome!

You can't search within sentences if you indexed a full text. You need to split the text by sentence and then index each sentence independently.

Otherwise you can do proximity search but the 2 terms might be in 2 different sentences (last word of one sentence and first word of the next sentence).

---

<div class="post-metadata">

### Author: ![Hamed\_Barati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hamed_barati/32/137779_2.png) [@Hamed\_Barati](https://discuss.elastic.co/u/Hamed_Barati)
#### Post date: [September 22, 2024, 12:33pm UTC](https://discuss.elastic.co/t/search-two-words-in-the-same-sentence/366914/4 "2024-09-22T12:33:39Z")

</div>

Thanks for answering me.  
I'm splitting sentences. Then, can I get position of token of searched words?  
If we get the position of word1 and word2, we can set a filter to compare sentences positions. Is it possible?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 23, 2024, 9:06am UTC](https://discuss.elastic.co/t/search-two-words-in-the-same-sentence/366914/5 "2024-09-23T09:06:15Z")

</div>

Do you have any sample document of what you are describing?

---

<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: [October 21, 2024, 9:07am UTC](https://discuss.elastic.co/t/search-two-words-in-the-same-sentence/366914/6 "2024-10-21T09:07:01Z")

</div>

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