# Analyzing SpanNearQuery

**URL:** <https://discuss.elastic.co/t/analyzing-spannearquery/4731>\
**Category:** Elasticsearch\
**Created:** [June 29, 2011, 8:27am UTC](https://discuss.elastic.co/t/analyzing-spannearquery/4731 "2011-06-29T08:27:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niko](https://avatars.discourse-cdn.com/v4/letter/n/91b2a8/32.png) [@Niko](https://discuss.elastic.co/u/Niko)\
**Post date:** [June 29, 2011, 8:27am UTC](https://discuss.elastic.co/t/analyzing-spannearquery/4731/1 "2011-06-29T08:27:06Z")

</div>

Hi everyone,

I have a question regarding SpanNearQueries. As I saw Term Queries  
were not analyzed before search, but are SpanNearQueries? Is there a  
way to analyze the SpanTermQueries inside of SpanNearQueries using the  
analyzer defined in the field mapping.

Thanks in advance.

Cheers,  
Niko

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [June 29, 2011, 10:25am UTC](https://discuss.elastic.co/t/analyzing-spannearquery/4731/2 "2011-06-29T10:25:46Z")

</div>

Hi Niko

> I have a question regarding SpanNearQueries. As I saw Term Queries  
> were not analyzed before search, but are SpanNearQueries? Is there a  
> way to analyze the SpanTermQueries inside of SpanNearQueries using the  
> analyzer defined in the field mapping.

Span queries are not analyzed either.

clint

---

<div class="post-metadata">

**Author:** ![Niko](https://avatars.discourse-cdn.com/v4/letter/n/91b2a8/32.png) [@Niko](https://discuss.elastic.co/u/Niko)\
**Post date:** [June 29, 2011, 10:28am UTC](https://discuss.elastic.co/t/analyzing-spannearquery/4731/3 "2011-06-29T10:28:44Z")

</div>

Hi Clint,

okay, is there a way to workaround? We would like to have analyzed terms  
within the SpanQuery, or is the only way to analyze by hand and put the  
terms then back into the SpanQuery?

Niko

2011/6/29 Clinton Gormley [clinton@iannounce.co.uk](mailto:clinton@iannounce.co.uk)

> Hi Niko
> 
> > I have a question regarding SpanNearQueries. As I saw Term Queries  
> > were not analyzed before search, but are SpanNearQueries? Is there a  
> > way to analyze the SpanTermQueries inside of SpanNearQueries using the  
> > analyzer defined in the field mapping.
> 
> Span queries are not analyzed either.
> 
> clint

## --

Gruß

Niko Gross

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [June 29, 2011, 10:36am UTC](https://discuss.elastic.co/t/analyzing-spannearquery/4731/4 "2011-06-29T10:36:38Z")

</div>

Hi Niko

> okay, is there a way to workaround? We would like to have analyzed  
> terms within the SpanQuery, or is the only way to analyze by hand and  
> put the terms then back into the SpanQuery?

Yes, I'm afraid that's the only way.

One way that you could approach it is to use the 'analyze' API. So you  
pass your text to ES, get the analyzed results back, then use those.

Not sure it is the most efficient way of doing it though.

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

clint

---

<div class="post-metadata">

**Author:** ![Niko](https://avatars.discourse-cdn.com/v4/letter/n/91b2a8/32.png) [@Niko](https://discuss.elastic.co/u/Niko)\
**Post date:** [June 29, 2011, 10:39am UTC](https://discuss.elastic.co/t/analyzing-spannearquery/4731/5 "2011-06-29T10:39:05Z")

</div>

Hi,

ok thanks. That what we thought we have to do.

Niko

2011/6/29 Clinton Gormley [clinton@iannounce.co.uk](mailto:clinton@iannounce.co.uk)

> Hi Niko
> 
> > okay, is there a way to workaround? We would like to have analyzed  
> > terms within the SpanQuery, or is the only way to analyze by hand and  
> > put the terms then back into the SpanQuery?
> 
> Yes, I'm afraid that's the only way.
> 
> One way that you could approach it is to use the 'analyze' API. So you  
> pass your text to ES, get the analyzed results back, then use those.
> 
> Not sure it is the most efficient way of doing it though.
> 
> [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze.html)
> 
> clint

## --

Gruß

Niko Gross

---

<div class="post-metadata">

**Author:** ![xam](https://avatars.discourse-cdn.com/v4/letter/x/bb73d2/32.png) [@xam](https://discuss.elastic.co/u/xam)\
**Post date:** [December 16, 2016, 10:36am UTC](https://discuss.elastic.co/t/analyzing-spannearquery/4731/6 "2016-12-16T10:36:23Z")

</div>

Hi all,

I just found this forum thread which is related to my problem.  
Is there anything new in Elasticsearch to avoid the workaround proposed by Clinton (as far as I know, it is not the case)?  
Maybe an enhancement to the workaround is to create a plugin on the ES side that does the analysis in order to avoid a query to the analysis API from the client side. Is it a correct approach?

Thanks,

---

<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 16, 2016, 10:39pm UTC](https://discuss.elastic.co/t/analyzing-spannearquery/4731/7 "2016-12-16T22:39:38Z")

</div>

If you using Java, I used to use the analysis service locally using the  
TransportClient. Not sure that is even possible, since so many useful  
workarounds have been closed. The issue does not stem from Elasticsearch,  
but Lucene, since that is where the limitation is.

---

<div class="post-metadata">

**Author:** ![xam](https://avatars.discourse-cdn.com/v4/letter/x/bb73d2/32.png) [@xam](https://discuss.elastic.co/u/xam)\
**Post date:** [December 29, 2016, 8:45am UTC](https://discuss.elastic.co/t/analyzing-spannearquery/4731/8 "2016-12-29T08:45:49Z")

</div>

Thank you,

I'll try this approach.

---

<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 30, 2016, 8:40pm UTC](https://discuss.elastic.co/t/analyzing-spannearquery/4731/9 "2016-12-30T20:40:39Z")

</div>

It should be clear that when I said the issue is in Lucene, I mean the need  
to pre-analyze tokens.

It used to be easy to create your own AnalysisService locally (if using the  
Java client), but I might have gotten difficult with each new version of  
Elasticsearch. I have not SpanQueries since 1.x. Just look at any unit  
tests for the analysis chain such as CharFilterTests:

2.4:

> <https://github.com/elastic/elasticsearch/blob/2.4/core/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java#L60>

5.0:

> <https://github.com/elastic/elasticsearch/blob/5.0/core/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java#L44>

master:  
[https://github.com/elastic/elasticsearch/blob/master/core/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java#L42](https://github.com/elastic/elasticsearch/blob/master/core/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java#L42)

In 2.x, all you needed was the injector. Now it seems that you cannot even  
create the AnalysisService (have not fully explored the new code).

Cheers,

Ivan

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:04pm UTC](https://discuss.elastic.co/t/analyzing-spannearquery/4731/10 "2017-07-05T22:04:36Z")

</div>


