# SpanNearQuery

**URL:** <https://discuss.elastic.co/t/spannearquery/69120>\
**Category:** Elasticsearch\
**Created:** [December 15, 2016, 6:19am UTC](https://discuss.elastic.co/t/spannearquery/69120 "2016-12-15T06:19:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![smile-sunsshine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smile-sunsshine/32/11470_2.png) [@smile-sunsshine](https://discuss.elastic.co/u/smile-sunsshine)\
**Post date:** [December 15, 2016, 6:19am UTC](https://discuss.elastic.co/t/spannearquery/69120/1 "2016-12-15T06:19:45Z")

</div>

Hi,everyone.

I want to use SpanNearQuery in my search request, i have set 'with\_positions\_offsets' to the 'term\_vector' option of a text field property in mapping when i created a index .And then i indexed some docs to my  
elasticsearch before i use SpanNearQuery to search my data.But it seems that the 'Slop' option of SpanNearQuery does not work ,the search result contains all matches data,no matter how far the distance between those words is.  
Did I miss something?Or something wrong with my search way?

Could anybody please help me? I am so lucky if anybody can give me some ideas about this.I use the Nest client,the version of it is 2.0,And the version of elasticsearch is 2.2.0  
Thank you !

---

<div class="post-metadata">

**Author:** ![mikemccand](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@mikemccand](https://discuss.elastic.co/u/mikemccand)\
**Post date:** [December 15, 2016, 10:46am UTC](https://discuss.elastic.co/t/spannearquery/69120/2 "2016-12-15T10:46:06Z")

</div>

Are you using a `type` = `string` field?

That should default to `index` = `analyzed` and `index_options` = `positions` which should make the span queries work.

Term vectors have nothing to do with searches finding matching documents; they are optionally used for highlighting.

Mike McCandless

---

<div class="post-metadata">

**Author:** ![smile-sunsshine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smile-sunsshine/32/11470_2.png) [@smile-sunsshine](https://discuss.elastic.co/u/smile-sunsshine)\
**Post date:** [December 16, 2016, 1:33am UTC](https://discuss.elastic.co/t/spannearquery/69120/3 "2016-12-16T01:33:27Z")

</div>

Thanks for your reply!

I used a type=string field,and specified “search\_analyzer”、“analyzer”、similarity”、“store”、“type” options for the Full-Text search field.

It is seems that the SpanNearQuery QueryContainer can not work together with FunctionScoreQuery.

Actually,I specified SpanNearQuery QueryContainer to the "Query" option of FunctionScoreQuery before i have some ideas on how to use SpanNearQuery.Then I found there was nothing related to SpanNearQuery in the JSON request to [ES.So](http://ES.So) I got my Full-Text QueryContainer by SpanNearQuery only,and the two option "slop" and "inorder" worked.I am so amazing,but i still can not understand that how the "slop" option control the "span\_term" clauses of SpanNearQuery.

---

<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:** [January 13, 2017, 1:33am UTC](https://discuss.elastic.co/t/spannearquery/69120/4 "2017-01-13T01:33:30Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
