# Get X word before and after search word

**URL:** <https://discuss.elastic.co/t/get-x-word-before-and-after-search-word/18154>\
**Category:** Elasticsearch\
**Created:** [June 17, 2014, 12:19pm UTC](https://discuss.elastic.co/t/get-x-word-before-and-after-search-word/18154 "2014-06-17T12:19:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Petr\_Jansky](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Petr\_Jansky](https://discuss.elastic.co/u/Petr_Jansky)\
**Post date:** [June 17, 2014, 12:19pm UTC](https://discuss.elastic.co/t/get-x-word-before-and-after-search-word/18154/1 "2014-06-17T12:19:39Z")

</div>

Hello,

I'm trying to find way how to get words/terms around search word eg let's  
have a document with text "The best search engine is ElasticSearch". I will  
search for "best" and get info that word "search" is xtime the next one  
after search words.

Thx  
Petr

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/4a1b4896-6263-4de2-ad45-dc5efd4df7a3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4a1b4896-6263-4de2-ad45-dc5efd4df7a3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [June 19, 2014, 9:11am UTC](https://discuss.elastic.co/t/get-x-word-before-and-after-search-word/18154/2 "2014-06-19T09:11:22Z")

</div>

Hey,

you potentially could use the termvectors API for this, see

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Not sure, if this is excalty, what you are after... maybe explain your  
use-case a bit more

--Alex

On Tue, Jun 17, 2014 at 2:19 PM, Petr Janský [petr.jansky@6hats.cz](mailto:petr.jansky@6hats.cz) wrote:

> Hello,
> 
> I'm trying to find way how to get words/terms around search word eg let's  
> have a document with text "The best search engine is Elasticsearch". I will  
> search for "best" and get info that word "search" is xtime the next one  
> after search words.
> 
> Thx  
> Petr
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/4a1b4896-6263-4de2-ad45-dc5efd4df7a3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4a1b4896-6263-4de2-ad45-dc5efd4df7a3%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/4a1b4896-6263-4de2-ad45-dc5efd4df7a3%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/4a1b4896-6263-4de2-ad45-dc5efd4df7a3%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM\_J4biH1Dbce%2Bqh6VYd3hzK1LQYk43Okj4zE52BocR6Mw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM_J4biH1Dbce%2Bqh6VYd3hzK1LQYk43Okj4zE52BocR6Mw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [June 19, 2014, 9:37pm UTC](https://discuss.elastic.co/t/get-x-word-before-and-after-search-word/18154/3 "2014-06-19T21:37:43Z")

</div>

Span queries are another option, but the main drawback is that they use  
non-analyzed term queries.

--  
Ivan

On Thu, Jun 19, 2014 at 2:11 AM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de) wrote:

> Hey,
> 
> you potentially could use the termvectors API for this, see  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-termvectors.html)
> 
> Not sure, if this is excalty, what you are after... maybe explain your  
> use-case a bit more
> 
> --Alex
> 
> On Tue, Jun 17, 2014 at 2:19 PM, Petr Janský [petr.jansky@6hats.cz](mailto:petr.jansky@6hats.cz) wrote:
> 
> > Hello,
> > 
> > I'm trying to find way how to get words/terms around search word eg let's  
> > have a document with text "The best search engine is Elasticsearch". I will  
> > search for "best" and get info that word "search" is xtime the next one  
> > after search words.
> > 
> > Thx  
> > Petr
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/4a1b4896-6263-4de2-ad45-dc5efd4df7a3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4a1b4896-6263-4de2-ad45-dc5efd4df7a3%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/4a1b4896-6263-4de2-ad45-dc5efd4df7a3%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/4a1b4896-6263-4de2-ad45-dc5efd4df7a3%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM\_J4biH1Dbce%2Bqh6VYd3hzK1LQYk43Okj4zE52BocR6Mw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM_J4biH1Dbce%2Bqh6VYd3hzK1LQYk43Okj4zE52BocR6Mw%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM\_J4biH1Dbce%2Bqh6VYd3hzK1LQYk43Okj4zE52BocR6Mw%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM_J4biH1Dbce%2Bqh6VYd3hzK1LQYk43Okj4zE52BocR6Mw%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBaEAJsB3HM7yRqd0kTWC-Qum627R%3DZLtLKVihVde\_xNw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBaEAJsB3HM7yRqd0kTWC-Qum627R%3DZLtLKVihVde_xNw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:21am UTC](https://discuss.elastic.co/t/get-x-word-before-and-after-search-word/18154/4 "2017-07-06T01:21:04Z")

</div>


