# Operators NEARx, BEFOR, AFTER, FIRSTx, LASTx

**URL:** <https://discuss.elastic.co/t/operators-nearx-befor-after-firstx-lastx/21607>\
**Category:** Elasticsearch\
**Created:** [January 13, 2015, 2:37pm UTC](https://discuss.elastic.co/t/operators-nearx-befor-after-firstx-lastx/21607 "2015-01-13T14:37:18Z")\
**Posts on this page:** 6\
**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:** [January 13, 2015, 2:37pm UTC](https://discuss.elastic.co/t/operators-nearx-befor-after-firstx-lastx/21607/1 "2015-01-13T14:37:18Z")

</div>

Hi there,

I'm looking for a way how to access span\_near and span\_first functionality  
to users via search box in gui that uses query string query.

1. Is there any easy way how to do it?
2. Will ElasticSeach folks implement operators like NEARx, BEFOR, AFTER,  
FIRSTx, LASTx to be able search by (using query string):
  - specific max word distance between key words
  - order of key words
  - word position of key word in field from start and end of field text

3. Span queries enable to use only terms, is there a way how to use  
words that will be analysed by lang. analyser - stemming etc.?

Thanks  
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/15d8acf6-83dd-4a11-bc7f-0377c2628035%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/15d8acf6-83dd-4a11-bc7f-0377c2628035%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [January 19, 2015, 9:02am UTC](https://discuss.elastic.co/t/operators-nearx-befor-after-firstx-lastx/21607/2 "2015-01-19T09:02:18Z")

</div>

Noone? ☹

Petr

Dne úterý 13. ledna 2015 15:37:18 UTC+1 Petr Janský napsal(a):

> Hi there,
> 
> I'm looking for a way how to access span\_near and span\_first functionality  
> to users via search box in gui that uses query string query.
> 
> 1. Is there any easy way how to do it?
> 2. Will ElasticSeach folks implement operators like NEARx, BEFOR,  
> AFTER, FIRSTx, LASTx to be able search by (using query string):
> - specific max word distance between key words
> - order of key words
> - word position of key word in field from start and end of field  
> text
> 
> 3. Span queries enable to use only terms, is there a way how to use  
> words that will be analysed by lang. analyser - stemming etc.?
> 
> Thanks  
> 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/f90a0eba-1b61-4a23-a2af-ec6a0c5e461f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f90a0eba-1b61-4a23-a2af-ec6a0c5e461f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [January 19, 2015, 9:22am UTC](https://discuss.elastic.co/t/operators-nearx-befor-after-firstx-lastx/21607/3 "2015-01-19T09:22:55Z")

</div>

Hi Petr,

let me try to address some of your questions:

ad 1) I am not sure I understand what you mean. If you want to use span  
type of query then simply use it instead of query string query. Especially,  
if you pass user input into the query then it is recommended NOT to use  
query string query and you should consider using different query type (like  
span query in your case).

ad 2) Not sure I fully understand but I can see match for some of those  
requested features in span queries. Like "slop". I would recommend you to  
read through chapters of "Proximity Matching" [1] to see how you can use  
"slop".

ad 3) The input that goes into span queries can go through text analysis  
process (as long as I am not mistaken). The fact that there are term  
queries behind the scene does not mean you can not process your analysis  
first.

May be if you can share some of your configs/documents/queries we can help  
you more.

[1]

> **[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.

Regards,  
Lukas

On Mon, Jan 19, 2015 at 10:02 AM, Petr Janský [petr.jansky@6hats.cz](mailto:petr.jansky@6hats.cz) wrote:

> Noone? ☹
> 
> Petr
> 
> Dne úterý 13. ledna 2015 15:37:18 UTC+1 Petr Janský napsal(a):
> 
> > Hi there,
> > 
> > I'm looking for a way how to access span\_near and span\_first  
> > functionality to users via search box in gui that uses query string query.
> > 
> > 1. Is there any easy way how to do it?
> > 2. Will ElasticSeach folks implement operators like NEARx, BEFOR,  
> > AFTER, FIRSTx, LASTx to be able search by (using query string):
> > - specific max word distance between key words
> > - order of key words
> > - word position of key word in field from start and end of field  
> > text
> > 
> > 3. Span queries enable to use only terms, is there a way how to use  
> > words that will be analysed by lang. analyser - stemming etc.?
> > 
> > Thanks  
> > 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/f90a0eba-1b61-4a23-a2af-ec6a0c5e461f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f90a0eba-1b61-4a23-a2af-ec6a0c5e461f%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/f90a0eba-1b61-4a23-a2af-ec6a0c5e461f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/f90a0eba-1b61-4a23-a2af-ec6a0c5e461f%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/CAO9cvUbmQvoJDFQ2aqQdy2eFLOH4RJja4KR\_\_hfyqanJfx2fmQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAO9cvUbmQvoJDFQ2aqQdy2eFLOH4RJja4KR__hfyqanJfx2fmQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [February 18, 2015, 11:35am UTC](https://discuss.elastic.co/t/operators-nearx-befor-after-firstx-lastx/21607/4 "2015-02-18T11:35:14Z")

</div>

Hi Lukas,

thank you for your answer. I checked the "Proximity Match" - "match\_phrase"  
and it's what I looking for. I'm only not able to find a way how to create  
queries like:

1. Obama BEFORE Iraq - the first word(not term) is before the second in  
a field text
2. "President Obama" AFTER Iraq - the phrase "President Obama" is after  
Iraq in a field text

In other words, the match\_phrase doesn't have in\_order parameter like  
span\_near and for span\_near I have to use terms - have to run analyzer for  
words befor.

Do you have any idea how to implement these queries?

Thanks  
Petr

Dne pondělí 19. ledna 2015 10:23:21 UTC+1 Lukáš Vlček napsal(a):

> Hi Petr,
> 
> let me try to address some of your questions:
> 
> ad 1) I am not sure I understand what you mean. If you want to use span  
> type of query then simply use it instead of query string query. Especially,  
> if you pass user input into the query then it is recommended NOT to use  
> query string query and you should consider using different query type (like  
> span query in your case).
> 
> ad 2) Not sure I fully understand but I can see match for some of those  
> requested features in span queries. Like "slop". I would recommend you to  
> read through chapters of "Proximity Matching" [1] to see how you can use  
> "slop".
> 
> ad 3) The input that goes into span queries can go through text analysis  
> process (as long as I am not mistaken). The fact that there are term  
> queries behind the scene does not mean you can not process your analysis  
> first.
> 
> May be if you can share some of your configs/documents/queries we can help  
> you more.
> 
> [1]  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/proximity-matching.html)
> 
> Regards,  
> Lukas
> 
> On Mon, Jan 19, 2015 at 10:02 AM, Petr Janský \<petr....@6hats.cz  
> \<javascript:\>\> wrote:
> 
> > Noone? ☹
> > 
> > Petr
> > 
> > Dne úterý 13. ledna 2015 15:37:18 UTC+1 Petr Janský napsal(a):
> > 
> > > Hi there,
> > > 
> > > I'm looking for a way how to access span\_near and span\_first  
> > > functionality to users via search box in gui that uses query string query.
> > > 
> > > 1. Is there any easy way how to do it?
> > > 2. Will ElasticSeach folks implement operators like NEARx, BEFOR,  
> > > AFTER, FIRSTx, LASTx to be able search by (using query string):
> > > - specific max word distance between key words
> > > - order of key words
> > > - word position of key word in field from start and end of field  
> > > text
> > > 
> > > 3. Span queries enable to use only terms, is there a way how to use  
> > > words that will be analysed by lang. analyser - stemming etc.?
> > > 
> > > Thanks  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/f90a0eba-1b61-4a23-a2af-ec6a0c5e461f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f90a0eba-1b61-4a23-a2af-ec6a0c5e461f%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/f90a0eba-1b61-4a23-a2af-ec6a0c5e461f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/f90a0eba-1b61-4a23-a2af-ec6a0c5e461f%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/8e88fb60-0e1c-423e-8208-a5e01206c620%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8e88fb60-0e1c-423e-8208-a5e01206c620%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [March 17, 2015, 1:59pm UTC](https://discuss.elastic.co/t/operators-nearx-befor-after-firstx-lastx/21607/5 "2015-03-17T13:59:57Z")

</div>

Noone? ☹

Petr

Dne středa 18. února 2015 12:35:15 UTC+1 Petr Janský napsal(a):

> Hi Lukas,
> 
> thank you for your answer. I checked the "Proximity Match" -  
> "match\_phrase" and it's what I looking for. I'm only not able to find a way  
> how to create queries like:
> 
> 1. Obama BEFORE Iraq - the first word(not term) is before the second  
> in a field text
> 2. "President Obama" AFTER Iraq - the phrase "President Obama" is  
> after Iraq in a field text
> 
> In other words, the match\_phrase doesn't have in\_order parameter like  
> span\_near and for span\_near I have to use terms - have to run analyzer for  
> words befor.
> 
> Do you have any idea how to implement these queries?
> 
> Thanks  
> Petr
> 
> Dne pondělí 19. ledna 2015 10:23:21 UTC+1 Lukáš Vlček napsal(a):
> 
> > Hi Petr,
> > 
> > let me try to address some of your questions:
> > 
> > ad 1) I am not sure I understand what you mean. If you want to use span  
> > type of query then simply use it instead of query string query. Especially,  
> > if you pass user input into the query then it is recommended NOT to use  
> > query string query and you should consider using different query type (like  
> > span query in your case).
> > 
> > ad 2) Not sure I fully understand but I can see match for some of those  
> > requested features in span queries. Like "slop". I would recommend you to  
> > read through chapters of "Proximity Matching" [1] to see how you can use  
> > "slop".
> > 
> > ad 3) The input that goes into span queries can go through text analysis  
> > process (as long as I am not mistaken). The fact that there are term  
> > queries behind the scene does not mean you can not process your analysis  
> > first.
> > 
> > May be if you can share some of your configs/documents/queries we can  
> > help you more.
> > 
> > [1]  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/proximity-matching.html)
> > 
> > Regards,  
> > Lukas
> > 
> > On Mon, Jan 19, 2015 at 10:02 AM, Petr Janský [petr....@6hats.cz](mailto:petr....@6hats.cz) wrote:
> > 
> > > Noone? ☹
> > > 
> > > Petr
> > > 
> > > Dne úterý 13. ledna 2015 15:37:18 UTC+1 Petr Janský napsal(a):
> > > 
> > > > Hi there,
> > > > 
> > > > I'm looking for a way how to access span\_near and span\_first  
> > > > functionality to users via search box in gui that uses query string query.
> > > > 
> > > > 1. Is there any easy way how to do it?
> > > > 2. Will ElasticSeach folks implement operators like NEARx, BEFOR,  
> > > > AFTER, FIRSTx, LASTx to be able search by (using query string):
> > > > - specific max word distance between key words
> > > > - order of key words
> > > > - word position of key word in field from start and end of field  
> > > > text
> > > > 
> > > > 3. Span queries enable to use only terms, is there a way how to use  
> > > > words that will be analysed by lang. analyser - stemming etc.?
> > > > 
> > > > Thanks  
> > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/f90a0eba-1b61-4a23-a2af-ec6a0c5e461f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f90a0eba-1b61-4a23-a2af-ec6a0c5e461f%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/f90a0eba-1b61-4a23-a2af-ec6a0c5e461f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/f90a0eba-1b61-4a23-a2af-ec6a0c5e461f%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/b49027e5-949d-4e35-8907-80dec5137efe%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b49027e5-949d-4e35-8907-80dec5137efe%40googlegroups.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, 12:26am UTC](https://discuss.elastic.co/t/operators-nearx-befor-after-firstx-lastx/21607/6 "2017-07-06T00:26:15Z")

</div>


