# Proximity phrase matching

**URL:** <https://discuss.elastic.co/t/proximity-phrase-matching/12256>\
**Category:** Elasticsearch\
**Created:** [June 4, 2013, 11:11am UTC](https://discuss.elastic.co/t/proximity-phrase-matching/12256 "2013-06-04T11:11:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hazzadous](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hazzadous/32/1654_2.png) [@hazzadous](https://discuss.elastic.co/u/hazzadous)\
**Post date:** [June 4, 2013, 11:11am UTC](https://discuss.elastic.co/t/proximity-phrase-matching/12256/1 "2013-06-04T11:11:58Z")

</div>

I'd like to support queries such as "one two" near "three four" which  
isn't supported by the query string syntax by the looks of it. The query  
would be run against a number of fields with differing analyzers. Currently  
we query using querystring and specify the fields we want to match against  
and this works well (the correct analysis is used for each field).  
However, trying to recreate this behaviour using spannears had some issues:

- span terms not being analyzed correctly
- the query dict had to be bool ored together at the very top to  
accomodate querying against the various fields (there's no way to specify  
multiple fields for spans)

For the analysis we could do that client side, but that sounds  
unsustainable. How would others tackle this? Would it be a simple patch  
to elasticsearch to support the above (perhaps extending the query syntax  
would be easy?). Where would I look to do this?

Thanks

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 5, 2013, 5:22am UTC](https://discuss.elastic.co/t/proximity-phrase-matching/12256/2 "2013-06-05T05:22:35Z")

</div>

There are various ways to achieve what you want, but none which are easy.  
Extending the query syntax is difficult since Elasticsearch is built on  
Lucene and the query syntax is the same. Creating a new query syntax means  
breaking the dependency on Lucene. Solr does have a SurroundQueryParser  
which supports span queries, but the terms are still not analyzed. Have you  
tried using phrase support in the match queries?

Span terms are not analyzed at all, so they are just not analyzed  
incorrectly. I bite the bullet an analyze the terms on the client side. And  
I also combine various span queries with a boolean query to support  
multiple fields (and DisMax queries as well). Not an ideal solution, but  
better than hacking a new query syntax IMHO.

Cheers,

IVan

On Tue, Jun 4, 2013 at 4:11 AM, hazzadous [hwaye@arachnys.com](mailto:hwaye@arachnys.com) wrote:

> I'd like to support queries such as "one two" near "three four" which  
> isn't supported by the query string syntax by the looks of it. The query  
> would be run against a number of fields with differing analyzers. Currently  
> we query using querystring and specify the fields we want to match against  
> and this works well (the correct analysis is used for each field).  
> However, trying to recreate this behaviour using spannears had some issues:
> 
> - span terms not being analyzed correctly
> - the query dict had to be bool ored together at the very top to  
> accomodate querying against the various fields (there's no way to specify  
> multiple fields for spans)
> 
> For the analysis we could do that client side, but that sounds  
> unsustainable. How would others tackle this? Would it be a simple patch  
> to elasticsearch to support the above (perhaps extending the query syntax  
> would be easy?). Where would I look to do this?
> 
> Thanks
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:32am UTC](https://discuss.elastic.co/t/proximity-phrase-matching/12256/3 "2017-07-06T02:32:52Z")

</div>


