# Searching words within a Sentence/paragraph

**URL:** <https://discuss.elastic.co/t/searching-words-within-a-sentence-paragraph/360044>\
**Category:** Elasticsearch\
**Created:** [May 23, 2024, 6:58am UTC](https://discuss.elastic.co/t/searching-words-within-a-sentence-paragraph/360044 "2024-05-23T06:58:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alok\_Tripathi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alok_tripathi/32/134736_2.png) [@Alok\_Tripathi](https://discuss.elastic.co/u/Alok_Tripathi)\
**Post date:** [May 23, 2024, 6:58am UTC](https://discuss.elastic.co/t/searching-words-within-a-sentence-paragraph/360044/1 "2024-05-23T06:58:11Z")

</div>

I want to search for words to be in same sentence/paragraph.  
Example: If I search for words "Bill", "Steve" then no document2 should be returned because both words exist in the same sentence. But if I search for "Bill" , "computer" then no document should be returned because both these words lies in two different sentences.

```auto
{
    "_index": "test",
    "_type": "_doc",
    "_id": "1",
    "_score": 1.0,
    "_source": {
        "content": "Bill Gates founded Microsoft. Steve Jobs founded Apple. They were both influential in the tech industry."
    }
},
{
    "_index": "test",
    "_type": "_doc",
    "_id": "2",
    "_score": 1.0,
    "_source": {
        "content": "Bill Gates and Steve Jobs were both pioneers in technology. They revolutionized the personal computer industry."
    }
}

```

---

<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:** [May 23, 2024, 7:22am UTC](https://discuss.elastic.co/t/searching-words-within-a-sentence-paragraph/360044/2 "2024-05-23T07:22:04Z")

</div>

Welcome!

You could use some proximity search but it won't be within a sentence. I mean that if you have something like: "I'm Bill. Steve is here." That will match as well.

Have a look at: [Query string query | Elasticsearch Guide [8.13] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_proximity_searches)

---

<div class="post-metadata">

**Author:** ![Alok\_Tripathi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alok_tripathi/32/134736_2.png) [@Alok\_Tripathi](https://discuss.elastic.co/u/Alok_Tripathi)\
**Post date:** [May 23, 2024, 7:39am UTC](https://discuss.elastic.co/t/searching-words-within-a-sentence-paragraph/360044/3 "2024-05-23T07:39:41Z")

</div>

If a store each sentence in a nested dictionary format with a unique key like:

```auto
{
    "_index": "test",
    "_type": "_doc",
    "_id": "1",
    "_score": 1.0,
    "_source": {
        "content" : {
            "sentence1" : "Bill Gates founded Microsoft. Steve Jobs founded Apple.",
            "sentence2" : "They were both influential in the tech industry."
        }
    }
},
{
    "_index": "test",
    "_type": "_doc",
    "_id": "2",
    "_score": 1.0,
    "_source": {
        "content" : {
            "sentence1" : "Bill Gates and Steve Jobs were both pioneers in technology.",
            "sentence2" : "They revolutionized the personal computer industry."
        }
        
    }
}

```

Can we perform search within single sentence now? Or storing each sentence in form of Array of sentences.

Can a custom sentence tokenizer will help to achieve this?
