# Phrase query matches across array elements?

**URL:** <https://discuss.elastic.co/t/phrase-query-matches-across-array-elements/9982>\
**Category:** Elasticsearch\
**Created:** [December 7, 2012, 12:24am UTC](https://discuss.elastic.co/t/phrase-query-matches-across-array-elements/9982 "2012-12-07T00:24:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anil\_Rhemtulla](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@Anil\_Rhemtulla](https://discuss.elastic.co/u/Anil_Rhemtulla)\
**Post date:** [December 7, 2012, 12:24am UTC](https://discuss.elastic.co/t/phrase-query-matches-across-array-elements/9982/1 "2012-12-07T00:24:28Z")

</div>

I have an index with a list of tags, very similar to the example in ES  
documentation for  
Arrays: [http://www.elasticsearch.org/guide/reference/mapping/array-type.html](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)

Using Elastic Head I can see the tags for a document in my index:  
tags: [  
"wanna",  
"money",  
"these",  
"thanks"  
]

When I perform a query\_string search with the text "wanna money" the  
document appears in the results, is this normal behavior?

I'm using ES 0.20 RC1, the field. I'm explicitly setting a mapping of the  
field to "string" with a snowball analyzer (I realize snowball is a little  
odd for tags, but there's a reason for it).

Thanks,  
Anil

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 7, 2012, 3:57pm UTC](https://discuss.elastic.co/t/phrase-query-matches-across-array-elements/9982/2 "2012-12-07T15:57:45Z")

</div>

Not sure I fully understand the issue. Are you looking for a phrase and  
don't want this record to show up because words in the phrase are indexed  
in different elements of the array?

On Thursday, December 6, 2012 7:24:28 PM UTC-5, Anil Rhemtulla wrote:

> I have an index with a list of tags, very similar to the example in ES  
> documentation for Arrays:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)
> 
> Using Elastic Head I can see the tags for a document in my index:  
> tags: [  
> "wanna",  
> "money",  
> "these",  
> "thanks"  
> ]
> 
> When I perform a query\_string search with the text "wanna money" the  
> document appears in the results, is this normal behavior?
> 
> I'm using ES 0.20 RC1, the field. I'm explicitly setting a mapping of the  
> field to "string" with a snowball analyzer (I realize snowball is a little  
> odd for tags, but there's a reason for it).
> 
> Thanks,  
> Anil

--

---

<div class="post-metadata">

**Author:** ![Anil\_Rhemtulla](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@Anil\_Rhemtulla](https://discuss.elastic.co/u/Anil_Rhemtulla)\
**Post date:** [December 7, 2012, 4:40pm UTC](https://discuss.elastic.co/t/phrase-query-matches-across-array-elements/9982/3 "2012-12-07T16:40:01Z")

</div>

Yes, that's correct. My assumption was that the separate array values would  
have large gaps in their offsets to avoid phrase matching. If phrase  
matching was desired then the field would be indexed as one big string  
instead of an array, doesn't that make sense? I must be missing something.

On Friday, December 7, 2012 7:57:45 AM UTC-8, Igor Motov wrote:

> Not sure I fully understand the issue. Are you looking for a phrase and  
> don't want this record to show up because words in the phrase are indexed  
> in different elements of the array?
> 
> On Thursday, December 6, 2012 7:24:28 PM UTC-5, Anil Rhemtulla wrote:
> 
> > I have an index with a list of tags, very similar to the example in ES  
> > documentation for Arrays:  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)
> > 
> > Using Elastic Head I can see the tags for a document in my index:  
> > tags: [  
> > "wanna",  
> > "money",  
> > "these",  
> > "thanks"  
> > ]
> > 
> > When I perform a query\_string search with the text "wanna money" the  
> > document appears in the results, is this normal behavior?
> > 
> > I'm using ES 0.20 RC1, the field. I'm explicitly setting a mapping of the  
> > field to "string" with a snowball analyzer (I realize snowball is a little  
> > odd for tags, but there's a reason for it).
> > 
> > Thanks,  
> > Anil

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 7, 2012, 5:01pm UTC](https://discuss.elastic.co/t/phrase-query-matches-across-array-elements/9982/4 "2012-12-07T17:01:33Z")

</div>

No, your assumption is correct, there is a configurable gap between  
instances of the same field, but the default value for this gap is 0. You  
can change it in the field mapping:

```
"tags" : {
      "type" : "string",
      "position_offset_gap": 100,
      .......  
}

```

On Friday, December 7, 2012 11:40:01 AM UTC-5, Anil Rhemtulla wrote:

> Yes, that's correct. My assumption was that the separate array values  
> would have large gaps in their offsets to avoid phrase matching. If phrase  
> matching was desired then the field would be indexed as one big string  
> instead of an array, doesn't that make sense? I must be missing something.
> 
> On Friday, December 7, 2012 7:57:45 AM UTC-8, Igor Motov wrote:
> 
> > Not sure I fully understand the issue. Are you looking for a phrase and  
> > don't want this record to show up because words in the phrase are indexed  
> > in different elements of the array?
> > 
> > On Thursday, December 6, 2012 7:24:28 PM UTC-5, Anil Rhemtulla wrote:
> > 
> > > I have an index with a list of tags, very similar to the example in ES  
> > > documentation for Arrays:  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)
> > > 
> > > Using Elastic Head I can see the tags for a document in my index:  
> > > tags: [  
> > > "wanna",  
> > > "money",  
> > > "these",  
> > > "thanks"  
> > > ]
> > > 
> > > When I perform a query\_string search with the text "wanna money" the  
> > > document appears in the results, is this normal behavior?
> > > 
> > > I'm using ES 0.20 RC1, the field. I'm explicitly setting a mapping of  
> > > the field to "string" with a snowball analyzer (I realize snowball is a  
> > > little odd for tags, but there's a reason for it).
> > > 
> > > Thanks,  
> > > Anil

--

---

<div class="post-metadata">

**Author:** ![Anil\_Rhemtulla](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@Anil\_Rhemtulla](https://discuss.elastic.co/u/Anil_Rhemtulla)\
**Post date:** [December 7, 2012, 6:40pm UTC](https://discuss.elastic.co/t/phrase-query-matches-across-array-elements/9982/5 "2012-12-07T18:40:37Z")

</div>

That worked like a charm, thanks!

I didn't see that option in the docs anywhere (I did find the git commit  
though), if you know of a good way to find options like this one please  
share your expertise! Do I need to start poking into the ES code?

Thanks again,  
Anil

On Friday, December 7, 2012 9:01:33 AM UTC-8, Igor Motov wrote:

> No, your assumption is correct, there is a configurable gap between  
> instances of the same field, but the default value for this gap is 0. You  
> can change it in the field mapping:
> 
> ```
> "tags" : {
> "type" : "string",
> "position_offset_gap": 100,
> .......  
> }
> 
> ```
> 
> On Friday, December 7, 2012 11:40:01 AM UTC-5, Anil Rhemtulla wrote:
> 
> > Yes, that's correct. My assumption was that the separate array values  
> > would have large gaps in their offsets to avoid phrase matching. If phrase  
> > matching was desired then the field would be indexed as one big string  
> > instead of an array, doesn't that make sense? I must be missing something.
> > 
> > On Friday, December 7, 2012 7:57:45 AM UTC-8, Igor Motov wrote:
> > 
> > > Not sure I fully understand the issue. Are you looking for a phrase and  
> > > don't want this record to show up because words in the phrase are indexed  
> > > in different elements of the array?
> > > 
> > > On Thursday, December 6, 2012 7:24:28 PM UTC-5, Anil Rhemtulla wrote:
> > > 
> > > > I have an index with a list of tags, very similar to the example in ES  
> > > > documentation for Arrays:  
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)
> > > > 
> > > > Using Elastic Head I can see the tags for a document in my index:  
> > > > tags: [  
> > > > "wanna",  
> > > > "money",  
> > > > "these",  
> > > > "thanks"  
> > > > ]
> > > > 
> > > > When I perform a query\_string search with the text "wanna money" the  
> > > > document appears in the results, is this normal behavior?
> > > > 
> > > > I'm using ES 0.20 RC1, the field. I'm explicitly setting a mapping of  
> > > > the field to "string" with a snowball analyzer (I realize snowball is a  
> > > > little odd for tags, but there's a reason for it).
> > > > 
> > > > Thanks,  
> > > > Anil

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 7, 2012, 9:53pm UTC](https://discuss.elastic.co/t/phrase-query-matches-across-array-elements/9982/6 "2012-12-07T21:53:11Z")

</div>

Yes, you are right, it wasn't documented. I added it.

On Friday, December 7, 2012 1:40:37 PM UTC-5, Anil Rhemtulla wrote:

> That worked like a charm, thanks!
> 
> I didn't see that option in the docs anywhere (I did find the git commit  
> though), if you know of a good way to find options like this one please  
> share your expertise! Do I need to start poking into the ES code?
> 
> Thanks again,  
> Anil
> 
> On Friday, December 7, 2012 9:01:33 AM UTC-8, Igor Motov wrote:
> 
> > No, your assumption is correct, there is a configurable gap between  
> > instances of the same field, but the default value for this gap is 0. You  
> > can change it in the field mapping:
> > 
> > ```
> > "tags" : {
> > "type" : "string",
> > "position_offset_gap": 100,
> > .......  
> > }
> > 
> > ```
> > 
> > On Friday, December 7, 2012 11:40:01 AM UTC-5, Anil Rhemtulla wrote:
> > 
> > > Yes, that's correct. My assumption was that the separate array values  
> > > would have large gaps in their offsets to avoid phrase matching. If phrase  
> > > matching was desired then the field would be indexed as one big string  
> > > instead of an array, doesn't that make sense? I must be missing something.
> > > 
> > > On Friday, December 7, 2012 7:57:45 AM UTC-8, Igor Motov wrote:
> > > 
> > > > Not sure I fully understand the issue. Are you looking for a phrase and  
> > > > don't want this record to show up because words in the phrase are indexed  
> > > > in different elements of the array?
> > > > 
> > > > On Thursday, December 6, 2012 7:24:28 PM UTC-5, Anil Rhemtulla wrote:
> > > > 
> > > > > I have an index with a list of tags, very similar to the example in ES  
> > > > > documentation for Arrays:  
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)
> > > > > 
> > > > > Using Elastic Head I can see the tags for a document in my index:  
> > > > > tags: [  
> > > > > "wanna",  
> > > > > "money",  
> > > > > "these",  
> > > > > "thanks"  
> > > > > ]
> > > > > 
> > > > > When I perform a query\_string search with the text "wanna money" the  
> > > > > document appears in the results, is this normal behavior?
> > > > > 
> > > > > I'm using ES 0.20 RC1, the field. I'm explicitly setting a mapping of  
> > > > > the field to "string" with a snowball analyzer (I realize snowball is a  
> > > > > little odd for tags, but there's a reason for it).
> > > > > 
> > > > > Thanks,  
> > > > > Anil

--

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:00am UTC](https://discuss.elastic.co/t/phrase-query-matches-across-array-elements/9982/7 "2017-07-06T03:00:46Z")

</div>


