# Controlling position offset gap between individual fields of \_all field

**URL:** <https://discuss.elastic.co/t/controlling-position-offset-gap-between-individual-fields-of--all-field/10111>\
**Category:** Elasticsearch\
**Created:** [December 18, 2012, 11:34pm UTC](https://discuss.elastic.co/t/controlling-position-offset-gap-between-individual-fields-of--all-field/10111 "2012-12-18T23:34:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)\
**Post date:** [December 18, 2012, 11:34pm UTC](https://discuss.elastic.co/t/controlling-position-offset-gap-between-individual-fields-of--all-field/10111/1 "2012-12-18T23:34:44Z")

</div>

Is there way to influence position offsets gap between individual fields in  
\_all field similar to how array's position\_offset\_gap flag functions?  
I would like to score of a hit on multiple terms of \_all originating from  
a single field to be higher than hit across multiple originating fields  
within \_all.  
Essentially the same as I can increase score of a a phrase match on a  
single array element vs that matching across multiple elements of an array

Thank you,  
Alex

--

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [December 19, 2012, 4:40pm UTC](https://discuss.elastic.co/t/controlling-position-offset-gap-between-individual-fields-of--all-field/10111/2 "2012-12-19T16:40:30Z")

</div>

The `_all` field adds all the values from the source fields as one  
stream of tokens. There isn't a way of influencing the position  
offsets gaps based on the source fields.

There is a different way you can achieve this. You can create your own  
all field with the use of multi-field. Lets say you have two fields in  
your mapping: name and description. You make both fields of type  
multi\_field, both of these multi\_fields included your own all field.  
Lets name this field 'my\_all'. If you give 'my\_all' field the same  
`index_name`, these fields point to the same field in the inverted  
index. This custom `my_all` field does take field boundaries into  
account specified with `position_offset_gap`.

I have created an example:

> <https://gist.github.com/martijnvg/4337178>

The can put the match phrase query as a should with a higher boost  
inside your main bool query.

Martijn

On 19 December 2012 00:34, AlexR [roytmana@gmail.com](mailto:roytmana@gmail.com) wrote:

> Is there way to influence position offsets gap between individual fields in  
> \_all field similar to how array's position\_offset\_gap flag functions?  
> I would like to score of a hit on multiple terms of \_all originating from  
> a single field to be higher than hit across multiple originating fields  
> within \_all.  
> Essentially the same as I can increase score of a a phrase match on a single  
> array element vs that matching across multiple elements of an array
> 
> Thank you,  
> Alex
> 
> --

--  
Met vriendelijke groet,

Martijn van Groningen

--

---

<div class="post-metadata">

**Author:** ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)\
**Post date:** [December 21, 2012, 10:27pm UTC](https://discuss.elastic.co/t/controlling-position-offset-gap-between-individual-fields-of--all-field/10111/3 "2012-12-21T22:27:06Z")

</div>

Thank you Martijn!  
Not just a hint but a complete example thanks again!

How will gap setting via multifield work for arrays whic will have their  
own gap setting?  
like this:  
field1field2array[0]array[1]field4

With over hundred of fields it will be quite a mapping if I had to do  
multifield for each field.  
I wonder if I am not better off just putting together a big composite field  
(array) myself. The only thing here I guess is that I will not be able to  
have different gaps between different fields or fields and arrays

To be honest, I am not sure using \_all (or equivalents) is the best  
strategy. I am very new to ES and lucene and do not have a good feel what  
work well and if I should try to use multifield queries rather than a  
synthetic \_all fields. But I am worried that there are too many fields and  
given a complex query it'll be a killer. plus I do not understand just how  
well multifield query scoring works (whether it is done via boolean or  
dismax)

I am about to post a big help me architectural question 🙂 part of which  
is use of multi field searches vs synthetic \_all field etc  
Hopefully someone will be kind enough to give me few suggestions as to  
which way to go

--

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [December 24, 2012, 2:50pm UTC](https://discuss.elastic.co/t/controlling-position-offset-gap-between-individual-fields-of--all-field/10111/4 "2012-12-24T14:50:01Z")

</div>

> How will gap setting via multifield work for arrays whic will have their own  
> gap setting?  
> like this:  
> field1field2array[0]array[1]field4  
> Not sure, but position wise the field gap can't be crossed. The array  
> gap depends on the position offset gap set in your custom all field.

> With over hundred of fields it will be quite a mapping if I had to do  
> multifield for each field.  
> I wonder if I am not better off just putting together a big composite field  
> (array) myself. The only thing here I guess is that I will not be able to  
> have different gaps between different fields or fields and arrays  
> Why would you want to have different position offset gaps? The use of this  
> settings is just not has phase query matches and highlight snippets  
> that cross the array element boundary.  
> Just one position offset gap is just fine.

> To be honest, I am not sure using \_all (or equivalents) is the best  
> strategy. I am very new to ES and lucene and do not have a good feel what  
> work well and if I should try to use multifield queries rather than a  
> synthetic \_all fields. But I am worried that there are too many fields and  
> given a complex query it'll be a killer. plus I do not understand just how  
> well multifield query scoring works (whether it is done via boolean or  
> dismax)  
> Nothing more different than scoring for a normal field. For scoring  
> it doesn't matter that the matching terms originate from different  
> array elements.

--

---

<div class="post-metadata">

**Author:** ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)\
**Post date:** [December 24, 2012, 4:23pm UTC](https://discuss.elastic.co/t/controlling-position-offset-gap-between-individual-fields-of--all-field/10111/5 "2012-12-24T16:23:21Z")

</div>

> With over hundred of fields it will be quite a mapping if I had to do

> > multifield for each field.  
> > I wonder if I am not better off just putting together a big composite  
> > field  
> > (array) myself. The only thing here I guess is that I will not be able  
> > to  
> > have different gaps between different fields or fields and arrays  
> > Why would you want to have different position offset gaps? The use of this  
> > settings is just not has phase query matches and highlight snippets  
> > that cross the array element boundary.  
> > Just one position offset gap is just fine.

Martijn,

My goal would be not to prevent matches across boundaries of fields that  
make up \_all (or similar composite field) but rather penalize (reduce  
scores) of such matches vs. match within an individual field. If I could  
control gaps between individual "pieces" of my "\_all"-like composite field  
I could use average field length (in words) to set reasonable gaps between  
such pieces in my composite field and use phrase query perhaps? For example  
field1, field2, field3 make up my composite field and these respective  
fields have 10, 20 and 30 average word count. gaps could be 20 for  
field1-field2 and 30 for field2-field3

But as I said it all might be fairly useless since in the end by combining  
fields into a composite one and searching it rather than individual fields  
does lose some of the precision.

If you had a JSON with over hundred pretty small text fields (3-5 to 15-20  
words long) and needed to search them all most of the time (plus faceting  
and search on some known fields and not much need for busting individual  
fields) would you search on \_all-like composite field or on individual  
fields using myrecord.\* multi-field search? Which should yield better  
relevance you think? How well multifield queries (particularly multifield  
phrase) calculate scores especially given large number of short fields  
involved. Will it be prohibitively expensive to search on such large number  
of fields

Thanks again,  
Alex

--

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:58am UTC](https://discuss.elastic.co/t/controlling-position-offset-gap-between-individual-fields-of--all-field/10111/6 "2017-07-06T02:58:33Z")

</div>


