# Wildcard Query within a Span

**URL:** https://discuss.elastic.co/t/wildcard-query-within-a-span/9607
**Category:** Elasticsearch
**Created:** [November 7, 2012, 7:57pm UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607 "2012-11-07T19:57:11Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Michael\_Sander](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander/32/838_2.png) [@Michael\_Sander](https://discuss.elastic.co/u/Michael_Sander)
#### Post date: [November 7, 2012, 7:57pm UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/1 "2012-11-07T19:57:11Z")

</div>

Hi,

Is it possible to construct an elasticsearch query (or filter) that detects  
whether two words with wildcards are within a certain distance of each  
other. Is this possible with elasticsearch?

For example, I would like a query that detects whether pret\* and ug\* are  
within five words of each other. Such a query should match "She is pretty  
and he is ugly."

I think I would need to use the span\_near query, but span\_near only accepts  
a series of span\_term's as arguments and span\_term doesn't appear to allow  
wildcards.

Is it possible to do this with elasticsearch? If not, is this possible with  
Lucene directly?

FYI, I have an SO question open here  
[http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)

--

---

<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: [November 7, 2012, 8:36pm UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/2 "2012-11-07T20:36:25Z")

</div>

Elasticsearch does not support Lucene's SpanRegexQuery or  
SpanMultiTermQueryWrapper. Not sure how difficult it is to expose it.

I believe there are some changes related to them in Lucene 4.0, so if  
anything was written for ES 0.20 and prior, it would need to be converted.

--  
Ivan

On Wed, Nov 7, 2012 at 11:57 AM, Michael Sander [michael.sander@gmail.com](mailto:michael.sander@gmail.com)wrote:

> Hi,
> 
> Is it possible to construct an elasticsearch query (or filter) that  
> detects whether two words with wildcards are within a certain distance of  
> each other. Is this possible with elasticsearch?
> 
> For example, I would like a query that detects whether pret\* and ug\* are  
> within five words of each other. Such a query should match "She is pretty  
> and he is ugly."
> 
> I think I would need to use the span\_near query, but span\_near only  
> accepts a series of span\_term's as arguments and span\_term doesn't appear  
> to allow wildcards.
> 
> Is it possible to do this with elasticsearch? If not, is this possible  
> with Lucene directly?
> 
> FYI, I have an SO question open here
> 
> [http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)
> 
> --

--

---

<div class="post-metadata">

### Author: ![Chris\_Male](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_male/32/2607_2.png) [@Chris\_Male](https://discuss.elastic.co/u/Chris_Male)
#### Post date: [November 8, 2012, 3:46am UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/3 "2012-11-08T03:46:00Z")

</div>

It is definitely possible to rig this sort of complex Query using Lucene.  
I would recommend maybe rolling your own QueryParser, maybe based on some  
of the existing, that creates the kind of Query you're looking for.

On Thursday, November 8, 2012 6:57:11 AM UTC+11, Michael Sander wrote:

> Hi,
> 
> Is it possible to construct an elasticsearch query (or filter) that  
> detects whether two words with wildcards are within a certain distance of  
> each other. Is this possible with elasticsearch?
> 
> For example, I would like a query that detects whether pret\* and ug\* are  
> within five words of each other. Such a query should match "She is pretty  
> and he is ugly."
> 
> I think I would need to use the span\_near query, but span\_near only  
> accepts a series of span\_term's as arguments and span\_term doesn't appear  
> to allow wildcards.
> 
> Is it possible to do this with elasticsearch? If not, is this possible  
> with Lucene directly?
> 
> FYI, I have an SO question open here
> 
> [http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)

--

---

<div class="post-metadata">

### Author: ![Michael\_Sander](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander/32/838_2.png) [@Michael\_Sander](https://discuss.elastic.co/u/Michael_Sander)
#### Post date: [November 8, 2012, 7:46pm UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/4 "2012-11-08T19:46:02Z")

</div>

Exposing SpanMultiTermQueryWrapper seems like the way to go. QueryParser  
may be more powerful, but I doubt it could be exposed through a generic  
interface. Any idea if this is possible with an elasticsearch plugin?

On Wednesday, November 7, 2012 10:46:00 PM UTC-5, Chris Male wrote:

> It is definitely possible to rig this sort of complex Query using Lucene.  
> I would recommend maybe rolling your own QueryParser, maybe based on some  
> of the existing, that creates the kind of Query you're looking for.
> 
> On Thursday, November 8, 2012 6:57:11 AM UTC+11, Michael Sander wrote:
> 
> > Hi,
> > 
> > Is it possible to construct an elasticsearch query (or filter) that  
> > detects whether two words with wildcards are within a certain distance of  
> > each other. Is this possible with elasticsearch?
> > 
> > For example, I would like a query that detects whether pret\* and ug\* are  
> > within five words of each other. Such a query should match "She is pretty  
> > and he is ugly."
> > 
> > I think I would need to use the span\_near query, but span\_near only  
> > accepts a series of span\_term's as arguments and span\_term doesn't appear  
> > to allow wildcards.
> > 
> > Is it possible to do this with elasticsearch? If not, is this possible  
> > with Lucene directly?
> > 
> > FYI, I have an SO question open here
> > 
> > [http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)

--

---

<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: [November 8, 2012, 8:46pm UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/5 "2012-11-08T20:46:14Z")

</div>

I have never done so, so I could be horribly wrong, but I assume all that  
we need to be done is the create a new  
org.elasticsearch.index.query.QueryParser that outputs the appropriate  
Lucene query and bind it inside IndicesQueriesModule.

On Thu, Nov 8, 2012 at 11:46 AM, Michael Sander [michael.sander@gmail.com](mailto:michael.sander@gmail.com)wrote:

> Exposing SpanMultiTermQueryWrapper seems like the way to go. QueryParser  
> may be more powerful, but I doubt it could be exposed through a generic  
> interface. Any idea if this is possible with an elasticsearch plugin?
> 
> On Wednesday, November 7, 2012 10:46:00 PM UTC-5, Chris Male wrote:
> 
> > It is definitely possible to rig this sort of complex Query using Lucene.  
> > I would recommend maybe rolling your own QueryParser, maybe based on some  
> > of the existing, that creates the kind of Query you're looking for.
> > 
> > On Thursday, November 8, 2012 6:57:11 AM UTC+11, Michael Sander wrote:
> > 
> > > Hi,
> > > 
> > > Is it possible to construct an elasticsearch query (or filter) that  
> > > detects whether two words with wildcards are within a certain distance of  
> > > each other. Is this possible with elasticsearch?
> > > 
> > > For example, I would like a query that detects whether pret\* and ug\* are  
> > > within five words of each other. Such a query should match "She is pretty  
> > > and he is ugly."
> > > 
> > > I think I would need to use the span\_near query, but span\_near only  
> > > accepts a series of span\_term's as arguments and span\_term doesn't appear  
> > > to allow wildcards.
> > > 
> > > Is it possible to do this with elasticsearch? If not, is this possible  
> > > with Lucene directly?
> > > 
> > > FYI, I have an SO question open here  
> > > [http://stackoverflow.com/\*\*questions/13258997/](http://stackoverflow.com/**questions/13258997/)\*\*  
> > > elasticsearch-query-wildcard- **or-stemming-within-a-span-i-e-**  
> > > proximity-query[http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)
> > > 
> > > --

--

---

<div class="post-metadata">

### Author: ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)
#### Post date: [November 9, 2012, 8:30am UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/6 "2012-11-09T08:30:29Z")

</div>

Hi Michael,

this kind of queries are possible but do you really wanna do this. Take a  
step back and think about how we would calculate relevance for this? I  
don't think you can expect a reasonable relevance score for such a query  
neither a reasonable performance. The fact that lucene allows these kind of  
queries is scary enough. 🙂 I'd really want to hear what you are trying  
to achieve and maybe we can find a better way to do this than multiterms  
spans. What is the usecase to allow queries like "pret\* and ug\*" who types  
that in? I mean I could imagine there are usecases like this (lawyers to  
weird things with searchengines in the patent space...) but maybe you can  
elaborate and we think about a better solution?

simon

On Wednesday, November 7, 2012 8:57:11 PM UTC+1, Michael Sander wrote:

> Hi,
> 
> Is it possible to construct an elasticsearch query (or filter) that  
> detects whether two words with wildcards are within a certain distance of  
> each other. Is this possible with elasticsearch?
> 
> For example, I would like a query that detects whether pret\* and ug\* are  
> within five words of each other. Such a query should match "She is pretty  
> and he is ugly."
> 
> I think I would need to use the span\_near query, but span\_near only  
> accepts a series of span\_term's as arguments and span\_term doesn't appear  
> to allow wildcards.
> 
> Is it possible to do this with elasticsearch? If not, is this possible  
> with Lucene directly?
> 
> FYI, I have an SO question open here
> 
> [http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)

--

---

<div class="post-metadata">

### Author: ![Michael\_Sander](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander/32/838_2.png) [@Michael\_Sander](https://discuss.elastic.co/u/Michael_Sander)
#### Post date: [November 9, 2012, 10:46pm UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/7 "2012-11-09T22:46:35Z")

</div>

Hi Simon,

Yes I really want to do this and your guess is correct: I am working on a  
legal research tool. Lawyers use surprisingly sophisticated queries to  
research law. For example, a lawyer researching employment discrimination  
lawsuits in New York may use the following query:

(employ\* within/5 discrimi\*) within/20 (black or latino or hispanic or  
(african within/3 american)) and "New York"

It seems complex, but searches like this occur all the time and such  
functionality is expected. It's one of the reasons Google scholar is not  
terribly popular with attorneys. Speed is important but not of extreme  
importance. A two or three second wait-time is not a deal breaker, but it  
definitely needs to be under ten. To make things run faster, I could limit  
wildcard queries to require at least four or five letters.

I will look into creating the plugin, however it does not look like a  
simple task.

On Friday, November 9, 2012 3:30:29 AM UTC-5, simonw wrote:

> Hi Michael,
> 
> this kind of queries are possible but do you really wanna do this. Take a  
> step back and think about how we would calculate relevance for this? I  
> don't think you can expect a reasonable relevance score for such a query  
> neither a reasonable performance. The fact that lucene allows these kind of  
> queries is scary enough. 🙂 I'd really want to hear what you are trying  
> to achieve and maybe we can find a better way to do this than multiterms  
> spans. What is the usecase to allow queries like "pret\* and ug\*" who types  
> that in? I mean I could imagine there are usecases like this (lawyers to  
> weird things with searchengines in the patent space...) but maybe you can  
> elaborate and we think about a better solution?
> 
> simon
> 
> On Wednesday, November 7, 2012 8:57:11 PM UTC+1, Michael Sander wrote:
> 
> > Hi,
> > 
> > Is it possible to construct an elasticsearch query (or filter) that  
> > detects whether two words with wildcards are within a certain distance of  
> > each other. Is this possible with elasticsearch?
> > 
> > For example, I would like a query that detects whether pret\* and ug\* are  
> > within five words of each other. Such a query should match "She is pretty  
> > and he is ugly."
> > 
> > I think I would need to use the span\_near query, but span\_near only  
> > accepts a series of span\_term's as arguments and span\_term doesn't appear  
> > to allow wildcards.
> > 
> > Is it possible to do this with elasticsearch? If not, is this possible  
> > with Lucene directly?
> > 
> > FYI, I have an SO question open here
> > 
> > [http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)

--

---

<div class="post-metadata">

### Author: ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)
#### Post date: [November 12, 2012, 8:56am UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/8 "2012-11-12T08:56:50Z")

</div>

On Friday, November 9, 2012 11:46:35 PM UTC+1, Michael Sander wrote:

> Hi Simon,
> 
> Yes I really want to do this and your guess is correct: I am working on a  
> legal research tool. Lawyers use surprisingly sophisticated queries to  
> research law. For example, a lawyer researching employment discrimination  
> lawsuits in New York may use the following query:
> 
> (employ\* within/5 discrimi\*) within/20 (black or latino or hispanic or  
> (african within/3 american)) and "New York"
> 
> It seems complex, but searches like this occur all the time and such  
> functionality is expected. It's one of the reasons Google scholar is not  
> terribly popular with attorneys. Speed is important but not of extreme  
> importance. A two or three second wait-time is not a deal breaker, but it  
> definitely needs to be under ten. To make things run faster, I could limit  
> wildcard queries to require at least four or five letters.
> 
> I will look into creating the plugin, however it does not look like a  
> simple task.

Hey Michael,

my first reaction: "Oh boy! - this looks very familiar :)"  
second reaction: "I knew it it must be legal space :)"

Yeah man I know what you are talking about, been there done that.... from a  
query perspective this doesn't seem too hard but it's certainly work to do.  
If you have questions please feel free to ask on the list. I will see in  
the meanwhile if it makes sense for us to add that to ES.

simon

> On Friday, November 9, 2012 3:30:29 AM UTC-5, simonw wrote:
> 
> > Hi Michael,
> > 
> > this kind of queries are possible but do you really wanna do this. Take a  
> > step back and think about how we would calculate relevance for this? I  
> > don't think you can expect a reasonable relevance score for such a query  
> > neither a reasonable performance. The fact that lucene allows these kind of  
> > queries is scary enough. 🙂 I'd really want to hear what you are trying  
> > to achieve and maybe we can find a better way to do this than multiterms  
> > spans. What is the usecase to allow queries like "pret\* and ug\*" who types  
> > that in? I mean I could imagine there are usecases like this (lawyers to  
> > weird things with searchengines in the patent space...) but maybe you can  
> > elaborate and we think about a better solution?
> > 
> > simon
> > 
> > On Wednesday, November 7, 2012 8:57:11 PM UTC+1, Michael Sander wrote:
> > 
> > > Hi,
> > > 
> > > Is it possible to construct an elasticsearch query (or filter) that  
> > > detects whether two words with wildcards are within a certain distance of  
> > > each other. Is this possible with elasticsearch?
> > > 
> > > For example, I would like a query that detects whether pret\* and ug\* are  
> > > within five words of each other. Such a query should match "She is pretty  
> > > and he is ugly."
> > > 
> > > I think I would need to use the span\_near query, but span\_near only  
> > > accepts a series of span\_term's as arguments and span\_term doesn't appear  
> > > to allow wildcards.
> > > 
> > > Is it possible to do this with elasticsearch? If not, is this possible  
> > > with Lucene directly?
> > > 
> > > FYI, I have an SO question open here
> > > 
> > > [http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)

--

---

<div class="post-metadata">

### Author: ![Michael\_Sander](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander/32/838_2.png) [@Michael\_Sander](https://discuss.elastic.co/u/Michael_Sander)
#### Post date: [November 12, 2012, 1:47pm UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/9 "2012-11-12T13:47:30Z")

</div>

Exposing lucene's SpanMultiTermQueryWrapper looks like the easiest way to  
support sophisticated queries.

I spent a few hours looking over the elasticsearch code and plugin  
architecture and I think it's possible to implement this in just a  
few lines of code. Unfortunately, I don't think the plugin system offers a  
way to install new query types as plugins. All of the QueryBuilders are  
hard-coded in QueryBuilders.java.

Is there a way to add new query types as a plugin? If not, maybe I'll just  
fork.

On Mon, Nov 12, 2012 at 3:56 AM, simonw  
[simon.willnauer@elasticsearch.com](mailto:simon.willnauer@elasticsearch.com)wrote:

> On Friday, November 9, 2012 11:46:35 PM UTC+1, Michael Sander wrote:
> 
> > Hi Simon,
> > 
> > Yes I really want to do this and your guess is correct: I am working on a  
> > legal research tool. Lawyers use surprisingly sophisticated queries to  
> > research law. For example, a lawyer researching employment discrimination  
> > lawsuits in New York may use the following query:
> > 
> > (employ\* within/5 discrimi\*) within/20 (black or latino or hispanic or  
> > (african within/3 american)) and "New York"
> > 
> > It seems complex, but searches like this occur all the time and such  
> > functionality is expected. It's one of the reasons Google scholar is not  
> > terribly popular with attorneys. Speed is important but not of extreme  
> > importance. A two or three second wait-time is not a deal breaker, but it  
> > definitely needs to be under ten. To make things run faster, I could limit  
> > wildcard queries to require at least four or five letters.
> > 
> > I will look into creating the plugin, however it does not look like a  
> > simple task.
> 
> Hey Michael,
> 
> my first reaction: "Oh boy! - this looks very familiar :)"  
> second reaction: "I knew it it must be legal space :)"
> 
> Yeah man I know what you are talking about, been there done that.... from  
> a query perspective this doesn't seem too hard but it's certainly work to  
> do. If you have questions please feel free to ask on the list. I will see  
> in the meanwhile if it makes sense for us to add that to ES.
> 
> simon
> 
> > On Friday, November 9, 2012 3:30:29 AM UTC-5, simonw wrote:
> > 
> > > Hi Michael,
> > > 
> > > this kind of queries are possible but do you really wanna do this. Take  
> > > a step back and think about how we would calculate relevance for this? I  
> > > don't think you can expect a reasonable relevance score for such a query  
> > > neither a reasonable performance. The fact that lucene allows these kind of  
> > > queries is scary enough. 🙂 I'd really want to hear what you are trying  
> > > to achieve and maybe we can find a better way to do this than multiterms  
> > > spans. What is the usecase to allow queries like "pret\* and ug\*" who types  
> > > that in? I mean I could imagine there are usecases like this (lawyers to  
> > > weird things with searchengines in the patent space...) but maybe you can  
> > > elaborate and we think about a better solution?
> > > 
> > > simon
> > > 
> > > On Wednesday, November 7, 2012 8:57:11 PM UTC+1, Michael Sander wrote:
> > > 
> > > > Hi,
> > > > 
> > > > Is it possible to construct an elasticsearch query (or filter) that  
> > > > detects whether two words with wildcards are within a certain distance of  
> > > > each other. Is this possible with elasticsearch?
> > > > 
> > > > For example, I would like a query that detects whether pret\* and ug\*  
> > > > are within five words of each other. Such a query should match "She is  
> > > > pretty and he is ugly."
> > > > 
> > > > I think I would need to use the span\_near query, but span\_near only  
> > > > accepts a series of span\_term's as arguments and span\_term doesn't appear  
> > > > to allow wildcards.
> > > > 
> > > > Is it possible to do this with elasticsearch? If not, is this possible  
> > > > with Lucene directly?
> > > > 
> > > > FYI, I have an SO question open here  
> > > > [http://stackoverflow.com/\*\*questions/13258997/](http://stackoverflow.com/**questions/13258997/)\*\*  
> > > > elasticsearch-query-wildcard- **or-stemming-within-a-span-i-e-**  
> > > > proximity-query[http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)
> > > > 
> > > > --

--

---

<div class="post-metadata">

### Author: ![Michael\_Sander](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander/32/838_2.png) [@Michael\_Sander](https://discuss.elastic.co/u/Michael_Sander)
#### Post date: [December 5, 2012, 2:22am UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/10 "2012-12-05T02:22:10Z")

</div>

FYI, I opened issue 2400 on the matter:

> <https://github.com/elastic/elasticsearch/issues/2400>
>
> Elasticsearch does not support lucene's SpanMultiTermQueryWrapper. This lucene q…uery allows users to form complicated queries such as wildcards or prefix queries embedded within span queries. These complex queries are regularly used in certain fields (e.g., legal research) and adding support for it would open ES up to a new field.
> 
> Unfortunately, adding support is not possible using a plugin because the plugin system offers no way to install new query types as plugins. All of the QueryBuilders are hard-coded in QueryBuilders.java.
> 
> This is not a bug, but a feature request to expose SpanMultiTermQueryWrapper to ES's query API.
> 
> Some additional information on this feature request can be found here:
> https://groups.google.com/forum/?fromgroups=#!topic/elasticsearch/vHQh0ARaAHY

On Monday, November 12, 2012 8:47:58 AM UTC-5, Michael Sander wrote:

> Exposing lucene's SpanMultiTermQueryWrapper looks like the easiest way to  
> support sophisticated queries.
> 
> I spent a few hours looking over the elasticsearch code and plugin  
> architecture and I think it's possible to implement this in just a  
> few lines of code. Unfortunately, I don't think the plugin system offers a  
> way to install new query types as plugins. All of the QueryBuilders are  
> hard-coded in QueryBuilders.java.
> 
> Is there a way to add new query types as a plugin? If not, maybe I'll just  
> fork.
> 
> On Mon, Nov 12, 2012 at 3:56 AM, simonw wrote:
> 
> > On Friday, November 9, 2012 11:46:35 PM UTC+1, Michael Sander wrote:
> > 
> > > Hi Simon,
> > > 
> > > Yes I really want to do this and your guess is correct: I am working on  
> > > a legal research tool. Lawyers use surprisingly sophisticated queries to  
> > > research law. For example, a lawyer researching employment discrimination  
> > > lawsuits in New York may use the following query:
> > > 
> > > (employ\* within/5 discrimi\*) within/20 (black or latino or hispanic or  
> > > (african within/3 american)) and "New York"
> > > 
> > > It seems complex, but searches like this occur all the time and such  
> > > functionality is expected. It's one of the reasons Google scholar is not  
> > > terribly popular with attorneys. Speed is important but not of extreme  
> > > importance. A two or three second wait-time is not a deal breaker, but it  
> > > definitely needs to be under ten. To make things run faster, I could limit  
> > > wildcard queries to require at least four or five letters.
> > > 
> > > I will look into creating the plugin, however it does not look like a  
> > > simple task.
> > 
> > Hey Michael,
> > 
> > my first reaction: "Oh boy! - this looks very familiar :)"  
> > second reaction: "I knew it it must be legal space :)"
> > 
> > Yeah man I know what you are talking about, been there done that.... from  
> > a query perspective this doesn't seem too hard but it's certainly work to  
> > do. If you have questions please feel free to ask on the list. I will see  
> > in the meanwhile if it makes sense for us to add that to ES.
> > 
> > simon
> > 
> > > On Friday, November 9, 2012 3:30:29 AM UTC-5, simonw wrote:
> > > 
> > > > Hi Michael,
> > > > 
> > > > this kind of queries are possible but do you really wanna do this. Take  
> > > > a step back and think about how we would calculate relevance for this? I  
> > > > don't think you can expect a reasonable relevance score for such a query  
> > > > neither a reasonable performance. The fact that lucene allows these kind of  
> > > > queries is scary enough. 🙂 I'd really want to hear what you are trying  
> > > > to achieve and maybe we can find a better way to do this than multiterms  
> > > > spans. What is the usecase to allow queries like "pret\* and ug\*" who types  
> > > > that in? I mean I could imagine there are usecases like this (lawyers to  
> > > > weird things with searchengines in the patent space...) but maybe you can  
> > > > elaborate and we think about a better solution?
> > > > 
> > > > simon
> > > > 
> > > > On Wednesday, November 7, 2012 8:57:11 PM UTC+1, Michael Sander wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > Is it possible to construct an elasticsearch query (or filter) that  
> > > > > detects whether two words with wildcards are within a certain distance of  
> > > > > each other. Is this possible with elasticsearch?
> > > > > 
> > > > > For example, I would like a query that detects whether pret\* and ug\*  
> > > > > are within five words of each other. Such a query should match "She is  
> > > > > pretty and he is ugly."
> > > > > 
> > > > > I think I would need to use the span\_near query, but span\_near only  
> > > > > accepts a series of span\_term's as arguments and span\_term doesn't appear  
> > > > > to allow wildcards.
> > > > > 
> > > > > Is it possible to do this with elasticsearch? If not, is this possible  
> > > > > with Lucene directly?
> > > > > 
> > > > > FYI, I have an SO question open here  
> > > > > [http://stackoverflow.com/\*\*questions/13258997/](http://stackoverflow.com/**questions/13258997/)\*\*  
> > > > > elasticsearch-query-wildcard- **or-stemming-within-a-span-i-e-**  
> > > > > proximity-query[http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)
> > > > > 
> > > > > --

--

---

<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: [December 5, 2012, 6:41am UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/11 "2012-12-05T06:41:24Z")

</div>

QueryBuilders methods are simple wrappers around the true constructors.  
They are nice to have, but not necessary.

On Tue, Dec 4, 2012 at 6:22 PM, Michael Sander [michael.sander@gmail.com](mailto:michael.sander@gmail.com)wrote:

> FYI, I opened issue 2400 on the matter:  
> [Query DSL: Support SpanMultiTermQueryWrapper · Issue #2400 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2400)
> 
> On Monday, November 12, 2012 8:47:58 AM UTC-5, Michael Sander wrote:
> 
> > Exposing lucene's \*\*SpanMultiTermQueryWrapper \*\*looks like the easiest  
> > way to support sophisticated queries.
> > 
> > I spent a few hours looking over the elasticsearch code and plugin  
> > architecture and I think it's possible to implement this in just a  
> > few lines of code. Unfortunately, I don't think the plugin system offers a  
> > way to install new query types as plugins. All of the QueryBuilders are  
> > hard-coded in QueryBuilders.java.
> > 
> > Is there a way to add new query types as a plugin? If not, maybe I'll  
> > just fork.
> > 
> > On Mon, Nov 12, 2012 at 3:56 AM, simonw wrote:
> > 
> > > On Friday, November 9, 2012 11:46:35 PM UTC+1, Michael Sander wrote:
> > > 
> > > > Hi Simon,
> > > > 
> > > > Yes I really want to do this and your guess is correct: I am working on  
> > > > a legal research tool. Lawyers use surprisingly sophisticated queries to  
> > > > research law. For example, a lawyer researching employment discrimination  
> > > > lawsuits in New York may use the following query:
> > > > 
> > > > (employ\* within/5 discrimi\*) within/20 (black or latino or hispanic or  
> > > > (african within/3 american)) and "New York"
> > > > 
> > > > It seems complex, but searches like this occur all the time and such  
> > > > functionality is expected. It's one of the reasons Google scholar is not  
> > > > terribly popular with attorneys. Speed is important but not of extreme  
> > > > importance. A two or three second wait-time is not a deal breaker, but it  
> > > > definitely needs to be under ten. To make things run faster, I could limit  
> > > > wildcard queries to require at least four or five letters.
> > > > 
> > > > I will look into creating the plugin, however it does not look like a  
> > > > simple task.
> > > 
> > > Hey Michael,
> > > 
> > > my first reaction: "Oh boy! - this looks very familiar :)"  
> > > second reaction: "I knew it it must be legal space :)"
> > > 
> > > Yeah man I know what you are talking about, been there done that....  
> > > from a query perspective this doesn't seem too hard but it's certainly work  
> > > to do. If you have questions please feel free to ask on the list. I will  
> > > see in the meanwhile if it makes sense for us to add that to ES.
> > > 
> > > simon
> > > 
> > > > On Friday, November 9, 2012 3:30:29 AM UTC-5, simonw wrote:
> > > > 
> > > > > Hi Michael,
> > > > > 
> > > > > this kind of queries are possible but do you really wanna do this.  
> > > > > Take a step back and think about how we would calculate relevance for this?  
> > > > > I don't think you can expect a reasonable relevance score for such a query  
> > > > > neither a reasonable performance. The fact that lucene allows these kind of  
> > > > > queries is scary enough. 🙂 I'd really want to hear what you are trying  
> > > > > to achieve and maybe we can find a better way to do this than multiterms  
> > > > > spans. What is the usecase to allow queries like "pret\* and ug\*" who types  
> > > > > that in? I mean I could imagine there are usecases like this (lawyers to  
> > > > > weird things with searchengines in the patent space...) but maybe you can  
> > > > > elaborate and we think about a better solution?
> > > > > 
> > > > > simon
> > > > > 
> > > > > On Wednesday, November 7, 2012 8:57:11 PM UTC+1, Michael Sander wrote:
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > Is it possible to construct an elasticsearch query (or filter) that  
> > > > > > detects whether two words with wildcards are within a certain distance of  
> > > > > > each other. Is this possible with elasticsearch?
> > > > > > 
> > > > > > For example, I would like a query that detects whether pret\* and ug\*  
> > > > > > are within five words of each other. Such a query should match "She is  
> > > > > > pretty and he is ugly."
> > > > > > 
> > > > > > I think I would need to use the span\_near query, but span\_near only  
> > > > > > accepts a series of span\_term's as arguments and span\_term doesn't appear  
> > > > > > to allow wildcards.
> > > > > > 
> > > > > > Is it possible to do this with elasticsearch? If not, is this  
> > > > > > possible with Lucene directly?
> > > > > > 
> > > > > > FYI, I have an SO question open here  
> > > > > > [http://stackoverflow.com/\*\*quest\*\*ions/13258997/\*\*elasticsearch-](http://stackoverflow.com/ **quest** ions/13258997/**elasticsearch-)\*\*  
> > > > > > query-wildcard-\*\*or-stemming-\*\*within-a-span-i-e-\*\*proximity-\*\*query[http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)
> > > > > > 
> > > > > > --
> > 
> > --

--

---

<div class="post-metadata">

### Author: ![Michael\_Sander](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander/32/838_2.png) [@Michael\_Sander](https://discuss.elastic.co/u/Michael_Sander)
#### Post date: [December 5, 2012, 7:07am UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/12 "2012-12-05T07:07:51Z")

</div>

I'm not sure I understand. Are you saying that it is possible to build a  
plugin that implements SpanMultiTermQueryWrapper?

On Wed, Dec 5, 2012 at 1:41 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> QueryBuilders methods are simple wrappers around the true constructors.  
> They are nice to have, but not necessary.
> 
> On Tue, Dec 4, 2012 at 6:22 PM, Michael Sander [michael.sander@gmail.com](mailto:michael.sander@gmail.com)wrote:
> 
> > FYI, I opened issue 2400 on the matter:  
> > [Query DSL: Support SpanMultiTermQueryWrapper · Issue #2400 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2400)
> > 
> > On Monday, November 12, 2012 8:47:58 AM UTC-5, Michael Sander wrote:
> > 
> > > Exposing lucene's \*\*SpanMultiTermQueryWrapper \*\*looks like the easiest  
> > > way to support sophisticated queries.
> > > 
> > > I spent a few hours looking over the elasticsearch code and plugin  
> > > architecture and I think it's possible to implement this in just a  
> > > few lines of code. Unfortunately, I don't think the plugin system offers a  
> > > way to install new query types as plugins. All of the QueryBuilders are  
> > > hard-coded in QueryBuilders.java.
> > > 
> > > Is there a way to add new query types as a plugin? If not, maybe I'll  
> > > just fork.
> > > 
> > > On Mon, Nov 12, 2012 at 3:56 AM, simonw wrote:
> > > 
> > > > On Friday, November 9, 2012 11:46:35 PM UTC+1, Michael Sander wrote:
> > > > 
> > > > > Hi Simon,
> > > > > 
> > > > > Yes I really want to do this and your guess is correct: I am working  
> > > > > on a legal research tool. Lawyers use surprisingly sophisticated queries  
> > > > > to research law. For example, a lawyer researching employment  
> > > > > discrimination lawsuits in New York may use the following query:
> > > > > 
> > > > > (employ\* within/5 discrimi\*) within/20 (black or latino or hispanic or  
> > > > > (african within/3 american)) and "New York"
> > > > > 
> > > > > It seems complex, but searches like this occur all the time and such  
> > > > > functionality is expected. It's one of the reasons Google scholar is not  
> > > > > terribly popular with attorneys. Speed is important but not of extreme  
> > > > > importance. A two or three second wait-time is not a deal breaker, but it  
> > > > > definitely needs to be under ten. To make things run faster, I could limit  
> > > > > wildcard queries to require at least four or five letters.
> > > > > 
> > > > > I will look into creating the plugin, however it does not look like a  
> > > > > simple task.
> > > > 
> > > > Hey Michael,
> > > > 
> > > > my first reaction: "Oh boy! - this looks very familiar :)"  
> > > > second reaction: "I knew it it must be legal space :)"
> > > > 
> > > > Yeah man I know what you are talking about, been there done that....  
> > > > from a query perspective this doesn't seem too hard but it's certainly work  
> > > > to do. If you have questions please feel free to ask on the list. I will  
> > > > see in the meanwhile if it makes sense for us to add that to ES.
> > > > 
> > > > simon
> > > > 
> > > > > On Friday, November 9, 2012 3:30:29 AM UTC-5, simonw wrote:
> > > > > 
> > > > > > Hi Michael,
> > > > > > 
> > > > > > this kind of queries are possible but do you really wanna do this.  
> > > > > > Take a step back and think about how we would calculate relevance for this?  
> > > > > > I don't think you can expect a reasonable relevance score for such a query  
> > > > > > neither a reasonable performance. The fact that lucene allows these kind of  
> > > > > > queries is scary enough. 🙂 I'd really want to hear what you are trying  
> > > > > > to achieve and maybe we can find a better way to do this than multiterms  
> > > > > > spans. What is the usecase to allow queries like "pret\* and ug\*" who types  
> > > > > > that in? I mean I could imagine there are usecases like this (lawyers to  
> > > > > > weird things with searchengines in the patent space...) but maybe you can  
> > > > > > elaborate and we think about a better solution?
> > > > > > 
> > > > > > simon
> > > > > > 
> > > > > > On Wednesday, November 7, 2012 8:57:11 PM UTC+1, Michael Sander wrote:
> > > > > > 
> > > > > > > Hi,
> > > > > > > 
> > > > > > > Is it possible to construct an elasticsearch query (or filter) that  
> > > > > > > detects whether two words with wildcards are within a certain distance of  
> > > > > > > each other. Is this possible with elasticsearch?
> > > > > > > 
> > > > > > > For example, I would like a query that detects whether pret\* and ug\*  
> > > > > > > are within five words of each other. Such a query should match "She is  
> > > > > > > pretty and he is ugly."
> > > > > > > 
> > > > > > > I think I would need to use the span\_near query, but span\_near only  
> > > > > > > accepts a series of span\_term's as arguments and span\_term doesn't appear  
> > > > > > > to allow wildcards.
> > > > > > > 
> > > > > > > Is it possible to do this with elasticsearch? If not, is this  
> > > > > > > possible with Lucene directly?
> > > > > > > 
> > > > > > > FYI, I have an SO question open here  
> > > > > > > [http://stackoverflow.com/\*\*quest\*\*ions/13258997/\*\*elasticsearch-](http://stackoverflow.com/ **quest** ions/13258997/**elasticsearch-)\*\*  
> > > > > > > query-wildcard-\*\*or-stemming-\*\*within-a-span-i-e-\*\*proximity-\*\*query[http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)
> > > > > > > 
> > > > > > > --
> > > 
> > > --
> 
> --

--

---

<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: [December 5, 2012, 5:11pm UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/13 "2012-12-05T17:11:27Z")

</div>

What I am saying is that the inability to modify QueryBuilders is not a  
stopping point. All it contains are helper methods, which are nice to have,  
but not a show-stopper. Are there other blocking points? Perhaps.  
Regardless, those Querys should be supported by Elasticsearch since they  
are native to Lucene.

Maybe I will try to add those myself. Looking at the commits, the ES team  
are working hard on Lucene 4.0. IIRC, span queries changed in Lucene 4, so  
perhaps they should finish the conversion first before working on new  
features that would to be ported.

--  
Ivan

On Tue, Dec 4, 2012 at 11:07 PM, Michael Sander [michael.sander@gmail.com](mailto:michael.sander@gmail.com)wrote:

> I'm not sure I understand. Are you saying that it is possible to build a  
> plugin that implements SpanMultiTermQueryWrapper?
> 
> On Wed, Dec 5, 2012 at 1:41 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:
> 
> > QueryBuilders methods are simple wrappers around the true constructors.  
> > They are nice to have, but not necessary.
> > 
> > On Tue, Dec 4, 2012 at 6:22 PM, Michael Sander [michael.sander@gmail.com](mailto:michael.sander@gmail.com)wrote:
> > 
> > > FYI, I opened issue 2400 on the matter:  
> > > [Query DSL: Support SpanMultiTermQueryWrapper · Issue #2400 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2400)
> > > 
> > > On Monday, November 12, 2012 8:47:58 AM UTC-5, Michael Sander wrote:
> > > 
> > > > Exposing lucene's \*\*SpanMultiTermQueryWrapper \*\*looks like the easiest  
> > > > way to support sophisticated queries.
> > > > 
> > > > I spent a few hours looking over the elasticsearch code and plugin  
> > > > architecture and I think it's possible to implement this in just a  
> > > > few lines of code. Unfortunately, I don't think the plugin system offers a  
> > > > way to install new query types as plugins. All of the QueryBuilders are  
> > > > hard-coded in QueryBuilders.java.
> > > > 
> > > > Is there a way to add new query types as a plugin? If not, maybe I'll  
> > > > just fork.
> > > > 
> > > > On Mon, Nov 12, 2012 at 3:56 AM, simonw wrote:
> > > > 
> > > > > On Friday, November 9, 2012 11:46:35 PM UTC+1, Michael Sander wrote:
> > > > > 
> > > > > > Hi Simon,
> > > > > > 
> > > > > > Yes I really want to do this and your guess is correct: I am working  
> > > > > > on a legal research tool. Lawyers use surprisingly sophisticated queries  
> > > > > > to research law. For example, a lawyer researching employment  
> > > > > > discrimination lawsuits in New York may use the following query:
> > > > > > 
> > > > > > (employ\* within/5 discrimi\*) within/20 (black or latino or hispanic  
> > > > > > or (african within/3 american)) and "New York"
> > > > > > 
> > > > > > It seems complex, but searches like this occur all the time and such  
> > > > > > functionality is expected. It's one of the reasons Google scholar is not  
> > > > > > terribly popular with attorneys. Speed is important but not of extreme  
> > > > > > importance. A two or three second wait-time is not a deal breaker, but it  
> > > > > > definitely needs to be under ten. To make things run faster, I could limit  
> > > > > > wildcard queries to require at least four or five letters.
> > > > > > 
> > > > > > I will look into creating the plugin, however it does not look like a  
> > > > > > simple task.
> > > > > 
> > > > > Hey Michael,
> > > > > 
> > > > > my first reaction: "Oh boy! - this looks very familiar :)"  
> > > > > second reaction: "I knew it it must be legal space :)"
> > > > > 
> > > > > Yeah man I know what you are talking about, been there done that....  
> > > > > from a query perspective this doesn't seem too hard but it's certainly work  
> > > > > to do. If you have questions please feel free to ask on the list. I will  
> > > > > see in the meanwhile if it makes sense for us to add that to ES.
> > > > > 
> > > > > simon
> > > > > 
> > > > > > On Friday, November 9, 2012 3:30:29 AM UTC-5, simonw wrote:
> > > > > > 
> > > > > > > Hi Michael,
> > > > > > > 
> > > > > > > this kind of queries are possible but do you really wanna do this.  
> > > > > > > Take a step back and think about how we would calculate relevance for this?  
> > > > > > > I don't think you can expect a reasonable relevance score for such a query  
> > > > > > > neither a reasonable performance. The fact that lucene allows these kind of  
> > > > > > > queries is scary enough. 🙂 I'd really want to hear what you are trying  
> > > > > > > to achieve and maybe we can find a better way to do this than multiterms  
> > > > > > > spans. What is the usecase to allow queries like "pret\* and ug\*" who types  
> > > > > > > that in? I mean I could imagine there are usecases like this (lawyers to  
> > > > > > > weird things with searchengines in the patent space...) but maybe you can  
> > > > > > > elaborate and we think about a better solution?
> > > > > > > 
> > > > > > > simon
> > > > > > > 
> > > > > > > On Wednesday, November 7, 2012 8:57:11 PM UTC+1, Michael Sander  
> > > > > > > wrote:
> > > > > > > 
> > > > > > > > Hi,
> > > > > > > > 
> > > > > > > > Is it possible to construct an elasticsearch query (or filter) that  
> > > > > > > > detects whether two words with wildcards are within a certain distance of  
> > > > > > > > each other. Is this possible with elasticsearch?
> > > > > > > > 
> > > > > > > > For example, I would like a query that detects whether pret\* and  
> > > > > > > > ug\* are within five words of each other. Such a query should match "She is  
> > > > > > > > pretty and he is ugly."
> > > > > > > > 
> > > > > > > > I think I would need to use the span\_near query, but span\_near only  
> > > > > > > > accepts a series of span\_term's as arguments and span\_term doesn't appear  
> > > > > > > > to allow wildcards.
> > > > > > > > 
> > > > > > > > Is it possible to do this with elasticsearch? If not, is this  
> > > > > > > > possible with Lucene directly?
> > > > > > > > 
> > > > > > > > FYI, I have an SO question open here  
> > > > > > > > [http://stackoverflow.com/\*\*quest\*\*ions/13258997/\*\*elasticsearch-](http://stackoverflow.com/ **quest** ions/13258997/**elasticsearch-)\*\*  
> > > > > > > > query-wildcard-\*\*or-stemming-\*\*within-a-span-i-e- **proximity-**  
> > > > > > > > query[http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)
> > > > > > > > 
> > > > > > > > --
> > > > 
> > > > --
> > 
> > --
> 
> --

--

---

<div class="post-metadata">

### Author: ![Christophe\_V](https://avatars.discourse-cdn.com/v4/letter/c/c6cbf5/32.png) [@Christophe\_V](https://discuss.elastic.co/u/Christophe_V)
#### Post date: [September 10, 2013, 9:20am UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/14 "2013-09-10T09:20:43Z")

</div>

Hi Michael,

I have the same need today to search on patent doc.  
Do you succeed to do use the span\_multi query on elasticsearch ? or do you  
migrate to another lucene search engine ?

thanks in advance for your feedback

regards

--  
Christophe

Le vendredi 9 novembre 2012 23:46:35 UTC+1, Michael Sander a écrit :

> Hi Simon,
> 
> Yes I really want to do this and your guess is correct: I am working on a  
> legal research tool. Lawyers use surprisingly sophisticated queries to  
> research law. For example, a lawyer researching employment discrimination  
> lawsuits in New York may use the following query:
> 
> (employ\* within/5 discrimi\*) within/20 (black or latino or hispanic or  
> (african within/3 american)) and "New York"
> 
> It seems complex, but searches like this occur all the time and such  
> functionality is expected. It's one of the reasons Google scholar is not  
> terribly popular with attorneys. Speed is important but not of extreme  
> importance. A two or three second wait-time is not a deal breaker, but it  
> definitely needs to be under ten. To make things run faster, I could limit  
> wildcard queries to require at least four or five letters.
> 
> I will look into creating the plugin, however it does not look like a  
> simple task.
> 
> On Friday, November 9, 2012 3:30:29 AM UTC-5, simonw wrote:
> 
> > Hi Michael,
> > 
> > this kind of queries are possible but do you really wanna do this. Take a  
> > step back and think about how we would calculate relevance for this? I  
> > don't think you can expect a reasonable relevance score for such a query  
> > neither a reasonable performance. The fact that lucene allows these kind of  
> > queries is scary enough. 🙂 I'd really want to hear what you are trying  
> > to achieve and maybe we can find a better way to do this than multiterms  
> > spans. What is the usecase to allow queries like "pret\* and ug\*" who types  
> > that in? I mean I could imagine there are usecases like this (lawyers to  
> > weird things with searchengines in the patent space...) but maybe you can  
> > elaborate and we think about a better solution?
> > 
> > simon
> > 
> > On Wednesday, November 7, 2012 8:57:11 PM UTC+1, Michael Sander wrote:
> > 
> > > Hi,
> > > 
> > > Is it possible to construct an elasticsearch query (or filter) that  
> > > detects whether two words with wildcards are within a certain distance of  
> > > each other. Is this possible with elasticsearch?
> > > 
> > > For example, I would like a query that detects whether pret\* and ug\* are  
> > > within five words of each other. Such a query should match "She is pretty  
> > > and he is ugly."
> > > 
> > > I think I would need to use the span\_near query, but span\_near only  
> > > accepts a series of span\_term's as arguments and span\_term doesn't appear  
> > > to allow wildcards.
> > > 
> > > Is it possible to do this with elasticsearch? If not, is this possible  
> > > with Lucene directly?
> > > 
> > > FYI, I have an SO question open here
> > > 
> > > [http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)

--  
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: ![Michael\_Sander](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander/32/838_2.png) [@Michael\_Sander](https://discuss.elastic.co/u/Michael_Sander)
#### Post date: [September 10, 2013, 11:42am UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/15 "2013-09-10T11:42:20Z")

</div>

Hi Cristophe,

Yes, I got it working using span\_multi. At the time I originally sent this  
message, span\_multi did not exist. However, it has been since added and  
works great.

I am curious... how you are using Elasticsearch in the patent space? My  
site also searches legal documents: [www.docketalarm.com/search](http://www.docketalarm.com/search)

Best,

Michael Sander  
[michael.sander@gmail.com](mailto:michael.sander@gmail.com)  
607-227-9859

On Tue, Sep 10, 2013 at 5:20 AM, Christophe V. [christophe.viaud@cewo.fr](mailto:christophe.viaud@cewo.fr)wrote:

> Hi Michael,
> 
> I have the same need today to search on patent doc.  
> Do you succeed to do use the span\_multi query on elasticsearch ? or do you  
> migrate to another lucene search engine ?
> 
> thanks in advance for your feedback
> 
> regards
> 
> --  
> Christophe
> 
> Le vendredi 9 novembre 2012 23:46:35 UTC+1, Michael Sander a écrit :
> 
> > Hi Simon,
> > 
> > Yes I really want to do this and your guess is correct: I am working on a  
> > legal research tool. Lawyers use surprisingly sophisticated queries to  
> > research law. For example, a lawyer researching employment discrimination  
> > lawsuits in New York may use the following query:
> > 
> > (employ\* within/5 discrimi\*) within/20 (black or latino or hispanic or  
> > (african within/3 american)) and "New York"
> > 
> > It seems complex, but searches like this occur all the time and such  
> > functionality is expected. It's one of the reasons Google scholar is not  
> > terribly popular with attorneys. Speed is important but not of extreme  
> > importance. A two or three second wait-time is not a deal breaker, but it  
> > definitely needs to be under ten. To make things run faster, I could limit  
> > wildcard queries to require at least four or five letters.
> > 
> > I will look into creating the plugin, however it does not look like a  
> > simple task.
> > 
> > On Friday, November 9, 2012 3:30:29 AM UTC-5, simonw wrote:
> > 
> > > Hi Michael,
> > > 
> > > this kind of queries are possible but do you really wanna do this. Take  
> > > a step back and think about how we would calculate relevance for this? I  
> > > don't think you can expect a reasonable relevance score for such a query  
> > > neither a reasonable performance. The fact that lucene allows these kind of  
> > > queries is scary enough. 🙂 I'd really want to hear what you are trying  
> > > to achieve and maybe we can find a better way to do this than multiterms  
> > > spans. What is the usecase to allow queries like "pret\* and ug\*" who types  
> > > that in? I mean I could imagine there are usecases like this (lawyers to  
> > > weird things with searchengines in the patent space...) but maybe you can  
> > > elaborate and we think about a better solution?
> > > 
> > > simon
> > > 
> > > On Wednesday, November 7, 2012 8:57:11 PM UTC+1, Michael Sander wrote:
> > > 
> > > > Hi,
> > > > 
> > > > Is it possible to construct an elasticsearch query (or filter) that  
> > > > detects whether two words with wildcards are within a certain distance of  
> > > > each other. Is this possible with elasticsearch?
> > > > 
> > > > For example, I would like a query that detects whether pret\* and ug\*  
> > > > are within five words of each other. Such a query should match "She is  
> > > > pretty and he is ugly."
> > > > 
> > > > I think I would need to use the span\_near query, but span\_near only  
> > > > accepts a series of span\_term's as arguments and span\_term doesn't appear  
> > > > to allow wildcards.
> > > > 
> > > > Is it possible to do this with elasticsearch? If not, is this possible  
> > > > with Lucene directly?
> > > > 
> > > > FYI, I have an SO question open here  
> > > > [http://stackoverflow.com/\*\*questions/13258997/](http://stackoverflow.com/**questions/13258997/)\*\*  
> > > > elasticsearch-query-wildcard- **or-stemming-within-a-span-i-e-**  
> > > > proximity-query[http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to a topic in the  
> > > > Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this topic, visit  
> > > > [https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe](https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe).  
> > > > To unsubscribe from this group and all its topics, 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: ![David\_Janssen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_janssen/32/2028_2.png) [@David\_Janssen](https://discuss.elastic.co/u/David_Janssen)
#### Post date: [October 24, 2013, 1:38pm UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/16 "2013-10-24T13:38:06Z")

</div>

Hi Michael,

I have the same requirements you got to 'convert' sophisticated queries  
into elasticsearch query dsl.

Would it be possible to get a JSON sample of multi\_span usage with complex  
proximity ?  
For example, what would be the right syntax for this request (is is  
possible to request that using ES ?) :

(toto and tata) within/20 (tutu or titi)

Best regards  
David

Le mardi 10 septembre 2013 13:42:20 UTC+2, Michael Sander a écrit :

> Hi Cristophe,
> 
> Yes, I got it working using span\_multi. At the time I originally sent this  
> message, span\_multi did not exist. However, it has been since added and  
> works great.
> 
> I am curious... how you are using Elasticsearch in the patent space? My  
> site also searches legal documents: [www.docketalarm.com/search](http://www.docketalarm.com/search)
> 
> Best,
> 
> Michael Sander  
> [michael.sander@gmail.com](mailto:michael.sander@gmail.com)  
> 607-227-9859
> 
> On Tue, Sep 10, 2013 at 5:20 AM, Christophe V. [christophe.viaud@cewo.fr](mailto:christophe.viaud@cewo.fr)wrote:
> 
> > Hi Michael,
> > 
> > I have the same need today to search on patent doc.  
> > Do you succeed to do use the span\_multi query on elasticsearch ? or do  
> > you migrate to another lucene search engine ?
> > 
> > thanks in advance for your feedback
> > 
> > regards
> > 
> > --  
> > Christophe
> > 
> > Le vendredi 9 novembre 2012 23:46:35 UTC+1, Michael Sander a écrit :
> > 
> > > Hi Simon,
> > > 
> > > Yes I really want to do this and your guess is correct: I am working on  
> > > a legal research tool. Lawyers use surprisingly sophisticated queries to  
> > > research law. For example, a lawyer researching employment discrimination  
> > > lawsuits in New York may use the following query:
> > > 
> > > (employ\* within/5 discrimi\*) within/20 (black or latino or hispanic or  
> > > (african within/3 american)) and "New York"
> > > 
> > > It seems complex, but searches like this occur all the time and such  
> > > functionality is expected. It's one of the reasons Google scholar is not  
> > > terribly popular with attorneys. Speed is important but not of extreme  
> > > importance. A two or three second wait-time is not a deal breaker, but it  
> > > definitely needs to be under ten. To make things run faster, I could limit  
> > > wildcard queries to require at least four or five letters.
> > > 
> > > I will look into creating the plugin, however it does not look like a  
> > > simple task.
> > > 
> > > On Friday, November 9, 2012 3:30:29 AM UTC-5, simonw wrote:
> > > 
> > > > Hi Michael,
> > > > 
> > > > this kind of queries are possible but do you really wanna do this. Take  
> > > > a step back and think about how we would calculate relevance for this? I  
> > > > don't think you can expect a reasonable relevance score for such a query  
> > > > neither a reasonable performance. The fact that lucene allows these kind of  
> > > > queries is scary enough. 🙂 I'd really want to hear what you are trying  
> > > > to achieve and maybe we can find a better way to do this than multiterms  
> > > > spans. What is the usecase to allow queries like "pret\* and ug\*" who types  
> > > > that in? I mean I could imagine there are usecases like this (lawyers to  
> > > > weird things with searchengines in the patent space...) but maybe you can  
> > > > elaborate and we think about a better solution?
> > > > 
> > > > simon
> > > > 
> > > > On Wednesday, November 7, 2012 8:57:11 PM UTC+1, Michael Sander wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > Is it possible to construct an elasticsearch query (or filter) that  
> > > > > detects whether two words with wildcards are within a certain distance of  
> > > > > each other. Is this possible with elasticsearch?
> > > > > 
> > > > > For example, I would like a query that detects whether pret\* and ug\*  
> > > > > are within five words of each other. Such a query should match "She is  
> > > > > pretty and he is ugly."
> > > > > 
> > > > > I think I would need to use the span\_near query, but span\_near only  
> > > > > accepts a series of span\_term's as arguments and span\_term doesn't appear  
> > > > > to allow wildcards.
> > > > > 
> > > > > Is it possible to do this with elasticsearch? If not, is this possible  
> > > > > with Lucene directly?
> > > > > 
> > > > > FYI, I have an SO question open here  
> > > > > [http://stackoverflow.com/\*\*questions/13258997/](http://stackoverflow.com/**questions/13258997/)\*\*  
> > > > > elasticsearch-query-wildcard- **or-stemming-within-a-span-i-e-**  
> > > > > proximity-query[http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to a topic in the  
> > > > > Google Groups "elasticsearch" group.  
> > > > > To unsubscribe from this topic, visit  
> > > > > [https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe](https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe).  
> > > > > To unsubscribe from this group and all its topics, 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: ![Michael\_Sander\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander_2/32/838_2.png) [@Michael\_Sander\_2](https://discuss.elastic.co/u/Michael_Sander_2)
#### Post date: [October 24, 2013, 2:51pm UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/17 "2013-10-24T14:51:22Z")

</div>

Hi David,

This is from one of my tests:

Input:  
'ferm! w/5 outil w/5 dispositif'  
Output:  
{  
'span\_near': {  
'clauses': [  
{'span\_multi': {'match': {'prefix': {'text': 'ferm'}}}},  
{'span\_near': {  
'clauses': [  
{'span\_term': {'text': 'outil'}},  
{'span\_term': {'text': 'dispositif'}}  
],  
'collect\_payloads': False,  
'in\_order': False,  
'slop': 4}  
}  
],  
'collect\_payloads': False,  
'in\_order': False,  
'slop': 4  
}  
} },

Michael Sander  
mes65@cornell.edu  
607-227-9859

On Thu, Oct 24, 2013 at 9:38 AM, [janssen.dja@gmail.com](mailto:janssen.dja@gmail.com) wrote:

> Hi Michael,
> 
> I have the same requirements you got to 'convert' sophisticated queries  
> into elasticsearch query dsl.
> 
> Would it be possible to get a JSON sample of multi\_span usage with  
> complex proximity ?  
> For example, what would be the right syntax for this request (is is  
> possible to request that using ES ?) :
> 
> (toto and tata) within/20 (tutu or titi)
> 
> Best regards  
> David
> 
> Le mardi 10 septembre 2013 13:42:20 UTC+2, Michael Sander a écrit :
> 
> > Hi Cristophe,
> > 
> > Yes, I got it working using span\_multi. At the time I originally sent  
> > this message, span\_multi did not exist. However, it has been since added  
> > and works great.
> > 
> > I am curious... how you are using Elasticsearch in the patent space? My  
> > site also searches legal documents: [www.docketalarm.com/search](http://www.docketalarm.com/search)
> > 
> > Best,
> > 
> > Michael Sander  
> > [michael.sander@gmail.com](mailto:michael.sander@gmail.com)  
> > 607-227-9859
> > 
> > On Tue, Sep 10, 2013 at 5:20 AM, Christophe V. [christophe.viaud@cewo.fr](mailto:christophe.viaud@cewo.fr)wrote:
> > 
> > > Hi Michael,
> > > 
> > > I have the same need today to search on patent doc.  
> > > Do you succeed to do use the span\_multi query on elasticsearch ? or do  
> > > you migrate to another lucene search engine ?
> > > 
> > > thanks in advance for your feedback
> > > 
> > > regards
> > > 
> > > --  
> > > Christophe
> > > 
> > > Le vendredi 9 novembre 2012 23:46:35 UTC+1, Michael Sander a écrit :
> > > 
> > > > Hi Simon,
> > > > 
> > > > Yes I really want to do this and your guess is correct: I am working on  
> > > > a legal research tool. Lawyers use surprisingly sophisticated queries to  
> > > > research law. For example, a lawyer researching employment discrimination  
> > > > lawsuits in New York may use the following query:
> > > > 
> > > > (employ\* within/5 discrimi\*) within/20 (black or latino or hispanic or  
> > > > (african within/3 american)) and "New York"
> > > > 
> > > > It seems complex, but searches like this occur all the time and such  
> > > > functionality is expected. It's one of the reasons Google scholar is not  
> > > > terribly popular with attorneys. Speed is important but not of extreme  
> > > > importance. A two or three second wait-time is not a deal breaker, but it  
> > > > definitely needs to be under ten. To make things run faster, I could limit  
> > > > wildcard queries to require at least four or five letters.
> > > > 
> > > > I will look into creating the plugin, however it does not look like a  
> > > > simple task.
> > > > 
> > > > On Friday, November 9, 2012 3:30:29 AM UTC-5, simonw wrote:
> > > > 
> > > > > Hi Michael,
> > > > > 
> > > > > this kind of queries are possible but do you really wanna do this.  
> > > > > Take a step back and think about how we would calculate relevance for this?  
> > > > > I don't think you can expect a reasonable relevance score for such a query  
> > > > > neither a reasonable performance. The fact that lucene allows these kind of  
> > > > > queries is scary enough. 🙂 I'd really want to hear what you are trying  
> > > > > to achieve and maybe we can find a better way to do this than multiterms  
> > > > > spans. What is the usecase to allow queries like "pret\* and ug\*" who types  
> > > > > that in? I mean I could imagine there are usecases like this (lawyers to  
> > > > > weird things with searchengines in the patent space...) but maybe you can  
> > > > > elaborate and we think about a better solution?
> > > > > 
> > > > > simon
> > > > > 
> > > > > On Wednesday, November 7, 2012 8:57:11 PM UTC+1, Michael Sander wrote:
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > Is it possible to construct an elasticsearch query (or filter) that  
> > > > > > detects whether two words with wildcards are within a certain distance of  
> > > > > > each other. Is this possible with elasticsearch?
> > > > > > 
> > > > > > For example, I would like a query that detects whether pret\* and ug\*  
> > > > > > are within five words of each other. Such a query should match "She is  
> > > > > > pretty and he is ugly."
> > > > > > 
> > > > > > I think I would need to use the span\_near query, but span\_near only  
> > > > > > accepts a series of span\_term's as arguments and span\_term doesn't appear  
> > > > > > to allow wildcards.
> > > > > > 
> > > > > > Is it possible to do this with elasticsearch? If not, is this  
> > > > > > possible with Lucene directly?
> > > > > > 
> > > > > > FYI, I have an SO question open here  
> > > > > > [http://stackoverflow.com/\*\*quest\*\*ions/13258997/\*\*elasticsearch-](http://stackoverflow.com/ **quest** ions/13258997/**elasticsearch-)\*\*  
> > > > > > query-wildcard-\*\*or-stemming-\*\*within-a-span-i-e-\*\*proximity-\*\*query[http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)
> > > > > > 
> > > > > > --  
> > > > > > You received this message because you are subscribed to a topic in the  
> > > > > > Google Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this topic, visit [https://groups.google.com/d/](https://groups.google.com/d/)\*\*  
> > > > > > topic/elasticsearch/\*\*vHQh0ARaAHY/unsubscribe[https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe](https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe)  
> > > > > > .  
> > > > > > To unsubscribe from this group and all its topics, send an email to  
> > > > > > elasticsearch+unsubscribe@\*\*[googlegroups.com](http://googlegroups.com)[elasticsearch%2Bunsubscribe@googlegroups.com](mailto:elasticsearch%2Bunsubscribe@googlegroups.com)  
> > > > > > .  
> > > > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > > .
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe](https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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: ![Michael\_Sander\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander_2/32/838_2.png) [@Michael\_Sander\_2](https://discuss.elastic.co/u/Michael_Sander_2)
#### Post date: [October 24, 2013, 2:52pm UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/18 "2013-10-24T14:52:29Z")

</div>

Here's another  
Input:  
foo w/3 (biz and bar)

Output:  
{  
"span\_near" : {  
"clauses" : [  
{ "span\_term" : { "text" : "foo" } },  
{ "span\_near" : {  
"clauses" : [  
{ "span\_term" : { "text" : "biz" } },  
{ "span\_term" : { "text" : "bar" } },  
],  
"slop" : int(1e6),  
"in\_order" : False,  
"collect\_payloads" : False  
} },  
],  
"slop" : 2,  
"in\_order" : False,  
"collect\_payloads" : False  
}  
}},

Michael Sander  
mes65@cornell.edu  
607-227-9859

On Thu, Oct 24, 2013 at 10:51 AM, Michael Sander [mes65@cornell.edu](mailto:mes65@cornell.edu) wrote:

> Hi David,
> 
> This is from one of my tests:
> 
> Input:  
> 'ferm! w/5 outil w/5 dispositif'  
> Output:  
> {  
> 'span\_near': {  
> 'clauses': [  
> {'span\_multi': {'match': {'prefix': {'text': 'ferm'}}}},  
> {'span\_near': {  
> 'clauses': [  
> {'span\_term': {'text': 'outil'}},  
> {'span\_term': {'text': 'dispositif'}}  
> ],  
> 'collect\_payloads': False,  
> 'in\_order': False,  
> 'slop': 4}  
> }  
> ],  
> 'collect\_payloads': False,  
> 'in\_order': False,  
> 'slop': 4  
> }  
> } },
> 
> Michael Sander  
> mes65@cornell.edu  
> 607-227-9859
> 
> On Thu, Oct 24, 2013 at 9:38 AM, [janssen.dja@gmail.com](mailto:janssen.dja@gmail.com) wrote:
> 
> > Hi Michael,
> > 
> > I have the same requirements you got to 'convert' sophisticated queries  
> > into elasticsearch query dsl.
> > 
> > Would it be possible to get a JSON sample of multi\_span usage with  
> > complex proximity ?  
> > For example, what would be the right syntax for this request (is is  
> > possible to request that using ES ?) :
> > 
> > (toto and tata) within/20 (tutu or titi)
> > 
> > Best regards  
> > David
> > 
> > Le mardi 10 septembre 2013 13:42:20 UTC+2, Michael Sander a écrit :
> > 
> > > Hi Cristophe,
> > > 
> > > Yes, I got it working using span\_multi. At the time I originally sent  
> > > this message, span\_multi did not exist. However, it has been since added  
> > > and works great.
> > > 
> > > I am curious... how you are using Elasticsearch in the patent space? My  
> > > site also searches legal documents: [www.docketalarm.com/search](http://www.docketalarm.com/search)
> > > 
> > > Best,
> > > 
> > > Michael Sander  
> > > [michael.sander@gmail.com](mailto:michael.sander@gmail.com)  
> > > 607-227-9859
> > > 
> > > On Tue, Sep 10, 2013 at 5:20 AM, Christophe V. \<[christophe.viaud@cewo.fr](mailto:christophe.viaud@cewo.fr)
> > > 
> > > > wrote:
> > > 
> > > > Hi Michael,
> > > > 
> > > > I have the same need today to search on patent doc.  
> > > > Do you succeed to do use the span\_multi query on elasticsearch ? or do  
> > > > you migrate to another lucene search engine ?
> > > > 
> > > > thanks in advance for your feedback
> > > > 
> > > > regards
> > > > 
> > > > --  
> > > > Christophe
> > > > 
> > > > Le vendredi 9 novembre 2012 23:46:35 UTC+1, Michael Sander a écrit :
> > > > 
> > > > > Hi Simon,
> > > > > 
> > > > > Yes I really want to do this and your guess is correct: I am working  
> > > > > on a legal research tool. Lawyers use surprisingly sophisticated queries  
> > > > > to research law. For example, a lawyer researching employment  
> > > > > discrimination lawsuits in New York may use the following query:
> > > > > 
> > > > > (employ\* within/5 discrimi\*) within/20 (black or latino or hispanic or  
> > > > > (african within/3 american)) and "New York"
> > > > > 
> > > > > It seems complex, but searches like this occur all the time and such  
> > > > > functionality is expected. It's one of the reasons Google scholar is not  
> > > > > terribly popular with attorneys. Speed is important but not of extreme  
> > > > > importance. A two or three second wait-time is not a deal breaker, but it  
> > > > > definitely needs to be under ten. To make things run faster, I could limit  
> > > > > wildcard queries to require at least four or five letters.
> > > > > 
> > > > > I will look into creating the plugin, however it does not look like a  
> > > > > simple task.
> > > > > 
> > > > > On Friday, November 9, 2012 3:30:29 AM UTC-5, simonw wrote:
> > > > > 
> > > > > > Hi Michael,
> > > > > > 
> > > > > > this kind of queries are possible but do you really wanna do this.  
> > > > > > Take a step back and think about how we would calculate relevance for this?  
> > > > > > I don't think you can expect a reasonable relevance score for such a query  
> > > > > > neither a reasonable performance. The fact that lucene allows these kind of  
> > > > > > queries is scary enough. 🙂 I'd really want to hear what you are trying  
> > > > > > to achieve and maybe we can find a better way to do this than multiterms  
> > > > > > spans. What is the usecase to allow queries like "pret\* and ug\*" who types  
> > > > > > that in? I mean I could imagine there are usecases like this (lawyers to  
> > > > > > weird things with searchengines in the patent space...) but maybe you can  
> > > > > > elaborate and we think about a better solution?
> > > > > > 
> > > > > > simon
> > > > > > 
> > > > > > On Wednesday, November 7, 2012 8:57:11 PM UTC+1, Michael Sander wrote:
> > > > > > 
> > > > > > > Hi,
> > > > > > > 
> > > > > > > Is it possible to construct an elasticsearch query (or filter) that  
> > > > > > > detects whether two words with wildcards are within a certain distance of  
> > > > > > > each other. Is this possible with elasticsearch?
> > > > > > > 
> > > > > > > For example, I would like a query that detects whether pret\* and ug\*  
> > > > > > > are within five words of each other. Such a query should match "She is  
> > > > > > > pretty and he is ugly."
> > > > > > > 
> > > > > > > I think I would need to use the span\_near query, but span\_near only  
> > > > > > > accepts a series of span\_term's as arguments and span\_term doesn't appear  
> > > > > > > to allow wildcards.
> > > > > > > 
> > > > > > > Is it possible to do this with elasticsearch? If not, is this  
> > > > > > > possible with Lucene directly?
> > > > > > > 
> > > > > > > FYI, I have an SO question open here  
> > > > > > > [http://stackoverflow.com/\*\*quest\*\*ions/13258997/\*\*elasticsearch-](http://stackoverflow.com/ **quest** ions/13258997/**elasticsearch-)\*\*  
> > > > > > > query-wildcard-\*\*or-stemming-\*\*within-a-span-i-e-\*\*proximity-\*\*query[http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)
> > > > > > > 
> > > > > > > --  
> > > > > > > You received this message because you are subscribed to a topic in the  
> > > > > > > Google Groups "elasticsearch" group.  
> > > > > > > To unsubscribe from this topic, visit [https://groups.google.com/d/](https://groups.google.com/d/)\*\*  
> > > > > > > topic/elasticsearch/\*\*vHQh0ARaAHY/unsubscribe[https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe](https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe)  
> > > > > > > .  
> > > > > > > To unsubscribe from this group and all its topics, send an email to  
> > > > > > > elasticsearch+unsubscribe@\*\*[googlegroups.com](http://googlegroups.com)[elasticsearch%2Bunsubscribe@googlegroups.com](mailto:elasticsearch%2Bunsubscribe@googlegroups.com)  
> > > > > > > .  
> > > > > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > > > .
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe](https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe).  
> > > To unsubscribe from this group and all its topics, 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: ![Michael\_Sander\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander_2/32/838_2.png) [@Michael\_Sander\_2](https://discuss.elastic.co/u/Michael_Sander_2)
#### Post date: [October 24, 2013, 2:53pm UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/19 "2013-10-24T14:53:13Z")

</div>

Note that these are python dictionaries, not JSON, but it's very similar,

Michael Sander  
mes65@cornell.edu  
607-227-9859

On Thu, Oct 24, 2013 at 10:52 AM, Michael Sander [mes65@cornell.edu](mailto:mes65@cornell.edu) wrote:

> Here's another  
> Input:  
> foo w/3 (biz and bar)
> 
> Output:  
> {  
> "span\_near" : {  
> "clauses" : [  
> { "span\_term" : { "text" : "foo" } },  
> { "span\_near" : {  
> "clauses" : [  
> { "span\_term" : { "text" : "biz" } },  
> { "span\_term" : { "text" : "bar" } },  
> ],  
> "slop" : int(1e6),  
> "in\_order" : False,  
> "collect\_payloads" : False  
> } },  
> ],  
> "slop" : 2,  
> "in\_order" : False,  
> "collect\_payloads" : False  
> }  
> }},
> 
> Michael Sander  
> mes65@cornell.edu  
> 607-227-9859
> 
> On Thu, Oct 24, 2013 at 10:51 AM, Michael Sander [mes65@cornell.edu](mailto:mes65@cornell.edu)wrote:
> 
> > Hi David,
> > 
> > This is from one of my tests:
> > 
> > Input:  
> > 'ferm! w/5 outil w/5 dispositif'  
> > Output:  
> > {  
> > 'span\_near': {  
> > 'clauses': [  
> > {'span\_multi': {'match': {'prefix': {'text': 'ferm'}}}},  
> > {'span\_near': {  
> > 'clauses': [  
> > {'span\_term': {'text': 'outil'}},  
> > {'span\_term': {'text': 'dispositif'}}  
> > ],  
> > 'collect\_payloads': False,  
> > 'in\_order': False,  
> > 'slop': 4}  
> > }  
> > ],  
> > 'collect\_payloads': False,  
> > 'in\_order': False,  
> > 'slop': 4  
> > }  
> > } },
> > 
> > Michael Sander  
> > mes65@cornell.edu  
> > 607-227-9859
> > 
> > On Thu, Oct 24, 2013 at 9:38 AM, [janssen.dja@gmail.com](mailto:janssen.dja@gmail.com) wrote:
> > 
> > > Hi Michael,
> > > 
> > > I have the same requirements you got to 'convert' sophisticated queries  
> > > into elasticsearch query dsl.
> > > 
> > > Would it be possible to get a JSON sample of multi\_span usage with  
> > > complex proximity ?  
> > > For example, what would be the right syntax for this request (is is  
> > > possible to request that using ES ?) :
> > > 
> > > (toto and tata) within/20 (tutu or titi)
> > > 
> > > Best regards  
> > > David
> > > 
> > > Le mardi 10 septembre 2013 13:42:20 UTC+2, Michael Sander a écrit :
> > > 
> > > > Hi Cristophe,
> > > > 
> > > > Yes, I got it working using span\_multi. At the time I originally sent  
> > > > this message, span\_multi did not exist. However, it has been since added  
> > > > and works great.
> > > > 
> > > > I am curious... how you are using Elasticsearch in the patent space?  
> > > > My site also searches legal documents: [www.docketalarm.com/search](http://www.docketalarm.com/search)
> > > > 
> > > > Best,
> > > > 
> > > > Michael Sander  
> > > > [michael.sander@gmail.com](mailto:michael.sander@gmail.com)  
> > > > 607-227-9859
> > > > 
> > > > On Tue, Sep 10, 2013 at 5:20 AM, Christophe V. \<  
> > > > [christophe.viaud@cewo.fr](mailto:christophe.viaud@cewo.fr)\> wrote:
> > > > 
> > > > > Hi Michael,
> > > > > 
> > > > > I have the same need today to search on patent doc.  
> > > > > Do you succeed to do use the span\_multi query on elasticsearch ? or do  
> > > > > you migrate to another lucene search engine ?
> > > > > 
> > > > > thanks in advance for your feedback
> > > > > 
> > > > > regards
> > > > > 
> > > > > --  
> > > > > Christophe
> > > > > 
> > > > > Le vendredi 9 novembre 2012 23:46:35 UTC+1, Michael Sander a écrit :
> > > > > 
> > > > > > Hi Simon,
> > > > > > 
> > > > > > Yes I really want to do this and your guess is correct: I am working  
> > > > > > on a legal research tool. Lawyers use surprisingly sophisticated queries  
> > > > > > to research law. For example, a lawyer researching employment  
> > > > > > discrimination lawsuits in New York may use the following query:
> > > > > > 
> > > > > > (employ\* within/5 discrimi\*) within/20 (black or latino or hispanic  
> > > > > > or (african within/3 american)) and "New York"
> > > > > > 
> > > > > > It seems complex, but searches like this occur all the time and such  
> > > > > > functionality is expected. It's one of the reasons Google scholar is not  
> > > > > > terribly popular with attorneys. Speed is important but not of extreme  
> > > > > > importance. A two or three second wait-time is not a deal breaker, but it  
> > > > > > definitely needs to be under ten. To make things run faster, I could limit  
> > > > > > wildcard queries to require at least four or five letters.
> > > > > > 
> > > > > > I will look into creating the plugin, however it does not look like a  
> > > > > > simple task.
> > > > > > 
> > > > > > On Friday, November 9, 2012 3:30:29 AM UTC-5, simonw wrote:
> > > > > > 
> > > > > > > Hi Michael,
> > > > > > > 
> > > > > > > this kind of queries are possible but do you really wanna do this.  
> > > > > > > Take a step back and think about how we would calculate relevance for this?  
> > > > > > > I don't think you can expect a reasonable relevance score for such a query  
> > > > > > > neither a reasonable performance. The fact that lucene allows these kind of  
> > > > > > > queries is scary enough. 🙂 I'd really want to hear what you are trying  
> > > > > > > to achieve and maybe we can find a better way to do this than multiterms  
> > > > > > > spans. What is the usecase to allow queries like "pret\* and ug\*" who types  
> > > > > > > that in? I mean I could imagine there are usecases like this (lawyers to  
> > > > > > > weird things with searchengines in the patent space...) but maybe you can  
> > > > > > > elaborate and we think about a better solution?
> > > > > > > 
> > > > > > > simon
> > > > > > > 
> > > > > > > On Wednesday, November 7, 2012 8:57:11 PM UTC+1, Michael Sander  
> > > > > > > wrote:
> > > > > > > 
> > > > > > > > Hi,
> > > > > > > > 
> > > > > > > > Is it possible to construct an elasticsearch query (or filter) that  
> > > > > > > > detects whether two words with wildcards are within a certain distance of  
> > > > > > > > each other. Is this possible with elasticsearch?
> > > > > > > > 
> > > > > > > > For example, I would like a query that detects whether pret\* and  
> > > > > > > > ug\* are within five words of each other. Such a query should match "She is  
> > > > > > > > pretty and he is ugly."
> > > > > > > > 
> > > > > > > > I think I would need to use the span\_near query, but span\_near only  
> > > > > > > > accepts a series of span\_term's as arguments and span\_term doesn't appear  
> > > > > > > > to allow wildcards.
> > > > > > > > 
> > > > > > > > Is it possible to do this with elasticsearch? If not, is this  
> > > > > > > > possible with Lucene directly?
> > > > > > > > 
> > > > > > > > FYI, I have an SO question open here  
> > > > > > > > [http://stackoverflow.com/\*\*quest\*\*ions/13258997/\*\*elasticsearch-](http://stackoverflow.com/ **quest** ions/13258997/**elasticsearch-)\*\*  
> > > > > > > > query-wildcard-\*\*or-stemming-\*\*within-a-span-i-e- **proximity-**  
> > > > > > > > query[http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)
> > > > > > > > 
> > > > > > > > --  
> > > > > > > > You received this message because you are subscribed to a topic in the  
> > > > > > > > Google Groups "elasticsearch" group.  
> > > > > > > > To unsubscribe from this topic, visit [https://groups.google.com/d/](https://groups.google.com/d/)\*\*  
> > > > > > > > topic/elasticsearch/\*\*vHQh0ARaAHY/unsubscribe[https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe](https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe)  
> > > > > > > > .  
> > > > > > > > To unsubscribe from this group and all its topics, send an email to  
> > > > > > > > elasticsearch+unsubscribe@\*\*[googlegroups.com](http://googlegroups.com)[elasticsearch%2Bunsubscribe@googlegroups.com](mailto:elasticsearch%2Bunsubscribe@googlegroups.com)  
> > > > > > > > .  
> > > > > > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > > > > .
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to a topic in the  
> > > > Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this topic, visit  
> > > > [https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe](https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe).  
> > > > To unsubscribe from this group and all its topics, 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: ![David\_Janssen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_janssen/32/2028_2.png) [@David\_Janssen](https://discuss.elastic.co/u/David_Janssen)
#### Post date: [October 25, 2013, 7:25am UTC](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607/20 "2013-10-25T07:25:25Z")

</div>

Thank you so much Michael,  
These samples are really helpful.

David

Le jeudi 24 octobre 2013 16:53:13 UTC+2, Michael Sander a écrit :

> Note that these are python dictionaries, not JSON, but it's very similar,
> 
> Michael Sander  
> me...@cornell.edu \<javascript:\>  
> 607-227-9859
> 
> On Thu, Oct 24, 2013 at 10:52 AM, Michael Sander \<me...@cornell.edu\<javascript:\>
> 
> > wrote:
> 
> > Here's another  
> > Input:  
> > foo w/3 (biz and bar)
> > 
> > Output:  
> > {  
> > "span\_near" : {  
> > "clauses" : [  
> > { "span\_term" : { "text" : "foo" } },  
> > { "span\_near" : {  
> > "clauses" : [  
> > { "span\_term" : { "text" : "biz" } },  
> > { "span\_term" : { "text" : "bar" } },  
> > ],  
> > "slop" : int(1e6),  
> > "in\_order" : False,  
> > "collect\_payloads" : False  
> > } },  
> > ],  
> > "slop" : 2,  
> > "in\_order" : False,  
> > "collect\_payloads" : False  
> > }  
> > }},
> > 
> > Michael Sander  
> > me...@cornell.edu \<javascript:\>  
> > 607-227-9859
> > 
> > On Thu, Oct 24, 2013 at 10:51 AM, Michael Sander \<me...@cornell.edu\<javascript:\>
> > 
> > > wrote:
> > 
> > > Hi David,
> > > 
> > > This is from one of my tests:
> > > 
> > > Input:  
> > > 'ferm! w/5 outil w/5 dispositif'  
> > > Output:  
> > > {  
> > > 'span\_near': {  
> > > 'clauses': [  
> > > {'span\_multi': {'match': {'prefix': {'text': 'ferm'}}}},  
> > > {'span\_near': {  
> > > 'clauses': [  
> > > {'span\_term': {'text': 'outil'}},  
> > > {'span\_term': {'text': 'dispositif'}}  
> > > ],  
> > > 'collect\_payloads': False,  
> > > 'in\_order': False,  
> > > 'slop': 4}  
> > > }  
> > > ],  
> > > 'collect\_payloads': False,  
> > > 'in\_order': False,  
> > > 'slop': 4  
> > > }  
> > > } },
> > > 
> > > Michael Sander  
> > > me...@cornell.edu \<javascript:\>  
> > > 607-227-9859
> > > 
> > > On Thu, Oct 24, 2013 at 9:38 AM, \<[janss...@gmail.com](mailto:janss...@gmail.com) \<javascript:\>\>wrote:
> > > 
> > > > Hi Michael,
> > > > 
> > > > I have the same requirements you got to 'convert' sophisticated queries  
> > > > into elasticsearch query dsl.
> > > > 
> > > > Would it be possible to get a JSON sample of multi\_span usage with  
> > > > complex proximity ?  
> > > > For example, what would be the right syntax for this request (is is  
> > > > possible to request that using ES ?) :
> > > > 
> > > > (toto and tata) within/20 (tutu or titi)
> > > > 
> > > > Best regards  
> > > > David
> > > > 
> > > > Le mardi 10 septembre 2013 13:42:20 UTC+2, Michael Sander a écrit :
> > > > 
> > > > > Hi Cristophe,
> > > > > 
> > > > > Yes, I got it working using span\_multi. At the time I originally sent  
> > > > > this message, span\_multi did not exist. However, it has been since added  
> > > > > and works great.
> > > > > 
> > > > > I am curious... how you are using Elasticsearch in the patent space?  
> > > > > My site also searches legal documents: [www.docketalarm.com/search](http://www.docketalarm.com/search)
> > > > > 
> > > > > Best,
> > > > > 
> > > > > Michael Sander  
> > > > > [michael...@gmail.com](mailto:michael...@gmail.com) \<javascript:\>  
> > > > > 607-227-9859
> > > > > 
> > > > > On Tue, Sep 10, 2013 at 5:20 AM, Christophe V. \<[christop...@cewo.fr](mailto:christop...@cewo.fr)\<javascript:\>
> > > > > 
> > > > > > wrote:
> > > > > 
> > > > > > Hi Michael,
> > > > > > 
> > > > > > I have the same need today to search on patent doc.  
> > > > > > Do you succeed to do use the span\_multi query on elasticsearch ? or  
> > > > > > do you migrate to another lucene search engine ?
> > > > > > 
> > > > > > thanks in advance for your feedback
> > > > > > 
> > > > > > regards
> > > > > > 
> > > > > > --  
> > > > > > Christophe
> > > > > > 
> > > > > > Le vendredi 9 novembre 2012 23:46:35 UTC+1, Michael Sander a écrit :
> > > > > > 
> > > > > > > Hi Simon,
> > > > > > > 
> > > > > > > Yes I really want to do this and your guess is correct: I am working  
> > > > > > > on a legal research tool. Lawyers use surprisingly sophisticated queries  
> > > > > > > to research law. For example, a lawyer researching employment  
> > > > > > > discrimination lawsuits in New York may use the following query:
> > > > > > > 
> > > > > > > (employ\* within/5 discrimi\*) within/20 (black or latino or hispanic  
> > > > > > > or (african within/3 american)) and "New York"
> > > > > > > 
> > > > > > > It seems complex, but searches like this occur all the time and such  
> > > > > > > functionality is expected. It's one of the reasons Google scholar is not  
> > > > > > > terribly popular with attorneys. Speed is important but not of extreme  
> > > > > > > importance. A two or three second wait-time is not a deal breaker, but it  
> > > > > > > definitely needs to be under ten. To make things run faster, I could limit  
> > > > > > > wildcard queries to require at least four or five letters.
> > > > > > > 
> > > > > > > I will look into creating the plugin, however it does not look like  
> > > > > > > a simple task.
> > > > > > > 
> > > > > > > On Friday, November 9, 2012 3:30:29 AM UTC-5, simonw wrote:
> > > > > > > 
> > > > > > > > Hi Michael,
> > > > > > > > 
> > > > > > > > this kind of queries are possible but do you really wanna do this.  
> > > > > > > > Take a step back and think about how we would calculate relevance for this?  
> > > > > > > > I don't think you can expect a reasonable relevance score for such a query  
> > > > > > > > neither a reasonable performance. The fact that lucene allows these kind of  
> > > > > > > > queries is scary enough. 🙂 I'd really want to hear what you are trying  
> > > > > > > > to achieve and maybe we can find a better way to do this than multiterms  
> > > > > > > > spans. What is the usecase to allow queries like "pret\* and ug\*" who types  
> > > > > > > > that in? I mean I could imagine there are usecases like this (lawyers to  
> > > > > > > > weird things with searchengines in the patent space...) but maybe you can  
> > > > > > > > elaborate and we think about a better solution?
> > > > > > > > 
> > > > > > > > simon
> > > > > > > > 
> > > > > > > > On Wednesday, November 7, 2012 8:57:11 PM UTC+1, Michael Sander  
> > > > > > > > wrote:
> > > > > > > > 
> > > > > > > > > Hi,
> > > > > > > > > 
> > > > > > > > > Is it possible to construct an elasticsearch query (or filter)  
> > > > > > > > > that detects whether two words with wildcards are within a certain distance  
> > > > > > > > > of each other. Is this possible with elasticsearch?
> > > > > > > > > 
> > > > > > > > > For example, I would like a query that detects whether pret\* and  
> > > > > > > > > ug\* are within five words of each other. Such a query should match "She is  
> > > > > > > > > pretty and he is ugly."
> > > > > > > > > 
> > > > > > > > > I think I would need to use the span\_near query, but span\_near  
> > > > > > > > > only accepts a series of span\_term's as arguments and span\_term doesn't  
> > > > > > > > > appear to allow wildcards.
> > > > > > > > > 
> > > > > > > > > Is it possible to do this with elasticsearch? If not, is this  
> > > > > > > > > possible with Lucene directly?
> > > > > > > > > 
> > > > > > > > > FYI, I have an SO question open here  
> > > > > > > > > [http://stackoverflow.com/\*\*quest\*\*ions/13258997/\*\*elasticsearch-](http://stackoverflow.com/ **quest** ions/13258997/**elasticsearch-)\*\*  
> > > > > > > > > query-wildcard-\*\*or-stemming-\*\*within-a-span-i-e- **proximity-**  
> > > > > > > > > query[http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query](http://stackoverflow.com/questions/13258997/elasticsearch-query-wildcard-or-stemming-within-a-span-i-e-proximity-query)
> > > > > > > > > 
> > > > > > > > > --  
> > > > > > > > > You received this message because you are subscribed to a topic in  
> > > > > > > > > the Google Groups "elasticsearch" group.  
> > > > > > > > > To unsubscribe from this topic, visit [https://groups.google.com/d/](https://groups.google.com/d/)\*\*  
> > > > > > > > > topic/elasticsearch/\*\*vHQh0ARaAHY/unsubscribe[https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe](https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe)  
> > > > > > > > > .  
> > > > > > > > > To unsubscribe from this group and all its topics, send an email to  
> > > > > > > > > elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com) \<javascript:\>.  
> > > > > > > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > > > > > .
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to a topic in the  
> > > > > Google Groups "elasticsearch" group.  
> > > > > To unsubscribe from this topic, visit  
> > > > > [https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe](https://groups.google.com/d/topic/elasticsearch/vHQh0ARaAHY/unsubscribe)  
> > > > > .  
> > > > > To unsubscribe from this group and all its topics, send an email to  
> > > > > [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > > > 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).

[Next page](https://discuss.elastic.co/t/wildcard-query-within-a-span/9607.md?page=2)
