# Number of matched positions as score

**URL:** <https://discuss.elastic.co/t/number-of-matched-positions-as-score/18414>\
**Category:** Elasticsearch\
**Created:** [July 1, 2014, 11:48am UTC](https://discuss.elastic.co/t/number-of-matched-positions-as-score/18414 "2014-07-01T11:48:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dany\_Gielow](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@Dany\_Gielow](https://discuss.elastic.co/u/Dany_Gielow)\
**Post date:** [July 1, 2014, 11:48am UTC](https://discuss.elastic.co/t/number-of-matched-positions-as-score/18414/1 "2014-07-01T11:48:10Z")

</div>

Hello,

I want to match only documents which match all positions.  
My approach would be to index the number of positions and compare it to the  
number of matched positions.

Every position that has multiple tokens (stacked tokens) should count only  
as 1.

Given the following positions in a field:  
_Position 1_: red  
_Position 2_: car, automobile

These queries should be scored as follows:

_"red"_: 1  
_"car"_: 1  
_"automobile"_: 1  
_"red car"_: 2  
_"red automobile"_: 2  
_"car automobile"_: 1  
_"fast red car"_: 2

What approach should I use to get the number of matched positions as a  
score?  
I guess I need a custom similarity for that.

Thanks in advance  
Dany

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [July 1, 2014, 12:11pm UTC](https://discuss.elastic.co/t/number-of-matched-positions-as-score/18414/2 "2014-07-01T12:11:10Z")

</div>

Hello Dany ,

I didnt really understand what you mean by position.  
Kindly clarify.

Thanks  
Vineeth

On Tue, Jul 1, 2014 at 5:18 PM, Dany Gielow [dany.gielow@gmail.com](mailto:dany.gielow@gmail.com) wrote:

> Hello,
> 
> I want to match only documents which match all positions.  
> My approach would be to index the number of positions and compare it to  
> the number of matched positions.
> 
> Every position that has multiple tokens (stacked tokens) should count only  
> as 1.
> 
> Given the following positions in a field:  
> _Position 1_: red  
> _Position 2_: car, automobile
> 
> These queries should be scored as follows:
> 
> _"red"_: 1  
> _"car"_: 1  
> _"automobile"_: 1  
> _"red car"_: 2  
> _"red automobile"_: 2  
> _"car automobile"_: 1  
> _"fast red car"_: 2
> 
> What approach should I use to get the number of matched positions as a  
> score?  
> I guess I need a custom similarity for that.
> 
> Thanks in advance  
> Dany
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5mSezCmfXK6TJDa-1GTX%3DWzercrmDb6-vsAXum%2B4C4Cvw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5mSezCmfXK6TJDa-1GTX%3DWzercrmDb6-vsAXum%2B4C4Cvw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Dany\_Gielow](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@Dany\_Gielow](https://discuss.elastic.co/u/Dany_Gielow)\
**Post date:** [July 1, 2014, 12:29pm UTC](https://discuss.elastic.co/t/number-of-matched-positions-as-score/18414/3 "2014-07-01T12:29:11Z")

</div>

Hi Vineeth,

The position is determined by the PositionIncrementAttribute in a Lucene  
TokenStream.  
So when I say multiple tokens at the same position, I mean tokens that have  
a positionIncrement of 0.

These tokens are generated by a SynonymFilter for example, which expands  
all synonyms. All these synonyms would have the same position.  
In my example "car" and "automobile" are synonyms which are expanded.

On Tuesday, July 1, 2014 2:11:17 PM UTC+2, vineeth mohan wrote:

> Hello Dany ,
> 
> I didnt really understand what you mean by position.  
> Kindly clarify.
> 
> Thanks  
> Vineeth
> 
> On Tue, Jul 1, 2014 at 5:18 PM, Dany Gielow \<[dany....@gmail.com](mailto:dany....@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hello,
> > 
> > I want to match only documents which match all positions.  
> > My approach would be to index the number of positions and compare it to  
> > the number of matched positions.
> > 
> > Every position that has multiple tokens (stacked tokens) should count  
> > only as 1.
> > 
> > Given the following positions in a field:  
> > _Position 1_: red  
> > _Position 2_: car, automobile
> > 
> > These queries should be scored as follows:
> > 
> > _"red"_: 1  
> > _"car"_: 1  
> > _"automobile"_: 1  
> > _"red car"_: 2  
> > _"red automobile"_: 2  
> > _"car automobile"_: 1  
> > _"fast red car"_: 2
> > 
> > What approach should I use to get the number of matched positions as a  
> > score?  
> > I guess I need a custom similarity for that.
> > 
> > Thanks in advance  
> > Dany
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/df6dcbf4-b542-445d-9b33-05a1a4bd1354%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/df6dcbf4-b542-445d-9b33-05a1a4bd1354%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [July 1, 2014, 1:27pm UTC](https://discuss.elastic.co/t/number-of-matched-positions-as-score/18414/4 "2014-07-01T13:27:28Z")

</div>

Hello Dany ,

This is ( surprisingly ) possible.

{  
"size": 30,  
"from": 0,  
"explain": true,  
"query": {  
"function\_score": {  
"query": {  
"query\_string": {  
"query": "red",  
"fields": [  
"message"  
]  
}  
},  
"functions": [  
{  
"script\_score": {  
"script": "termInfo = \_index['message'].get('red',\_POSITIONS |  
\_CACHE);positions = ;score = 0;for (pos : termInfo) {  
if(positions.contains(pos.position)){ ;next;} score = score +  
pos.position;positions.add(pos.position)}return positions.size();"  
}  
}  
],  
"boost\_mode": "replace"  
}  
}  
}

In the scripting in function\_score , you can access the position and the  
use this programatically to find the score.  
I have done an example usage above and it works in the latest version.

More documentation -

> **[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.

> **[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.

Thanks  
Vineeth

On Tue, Jul 1, 2014 at 5:59 PM, Dany Gielow [dany.gielow@gmail.com](mailto:dany.gielow@gmail.com) wrote:

> Hi Vineeth,
> 
> The position is determined by the PositionIncrementAttribute in a Lucene  
> TokenStream.  
> So when I say multiple tokens at the same position, I mean tokens that  
> have a positionIncrement of 0.
> 
> These tokens are generated by a SynonymFilter for example, which expands  
> all synonyms. All these synonyms would have the same position.  
> In my example "car" and "automobile" are synonyms which are expanded.
> 
> On Tuesday, July 1, 2014 2:11:17 PM UTC+2, vineeth mohan wrote:
> 
> > Hello Dany ,
> > 
> > I didnt really understand what you mean by position.  
> > Kindly clarify.
> > 
> > Thanks  
> > Vineeth
> > 
> > On Tue, Jul 1, 2014 at 5:18 PM, Dany Gielow [dany....@gmail.com](mailto:dany....@gmail.com) wrote:
> > 
> > > Hello,
> > > 
> > > I want to match only documents which match all positions.  
> > > My approach would be to index the number of positions and compare it to  
> > > the number of matched positions.
> > > 
> > > Every position that has multiple tokens (stacked tokens) should count  
> > > only as 1.
> > > 
> > > Given the following positions in a field:  
> > > _Position 1_: red  
> > > _Position 2_: car, automobile
> > > 
> > > These queries should be scored as follows:
> > > 
> > > _"red"_: 1  
> > > _"car"_: 1  
> > > _"automobile"_: 1  
> > > _"red car"_: 2  
> > > _"red automobile"_: 2  
> > > _"car automobile"_: 1  
> > > _"fast red car"_: 2
> > > 
> > > What approach should I use to get the number of matched positions as a  
> > > score?  
> > > I guess I need a custom similarity for that.
> > > 
> > > Thanks in advance  
> > > Dany
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > 
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%  
> > > [40googlegroups.com](http://40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > 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).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/df6dcbf4-b542-445d-9b33-05a1a4bd1354%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/df6dcbf4-b542-445d-9b33-05a1a4bd1354%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/df6dcbf4-b542-445d-9b33-05a1a4bd1354%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/df6dcbf4-b542-445d-9b33-05a1a4bd1354%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nd4pPM3nC97jbChkGbW\_RbAToxKQtkaJVmT7eB8P9gsw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nd4pPM3nC97jbChkGbW_RbAToxKQtkaJVmT7eB8P9gsw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Dany\_Gielow](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@Dany\_Gielow](https://discuss.elastic.co/u/Dany_Gielow)\
**Post date:** [July 1, 2014, 1:51pm UTC](https://discuss.elastic.co/t/number-of-matched-positions-as-score/18414/5 "2014-07-01T13:51:14Z")

</div>

Hello Vineeth,

Your script works like a charm. Thank you very much.

I will probably write a native script function, which will support multiple  
query terms.

Thank you again  
Dany

On Tuesday, July 1, 2014 3:27:36 PM UTC+2, vineeth mohan wrote:

> Hello Dany ,
> 
> This is ( surprisingly ) possible.
> 
> {  
> "size": 30,  
> "from": 0,  
> "explain": true,  
> "query": {  
> "function\_score": {  
> "query": {  
> "query\_string": {  
> "query": "red",  
> "fields": [  
> "message"  
> ]  
> }  
> },  
> "functions": [  
> {  
> "script\_score": {  
> "script": "termInfo = \_index['message'].get('red',\_POSITIONS |  
> \_CACHE);positions = ;score = 0;for (pos : termInfo) {  
> if(positions.contains(pos.position)){ ;next;} score = score +  
> pos.position;positions.add(pos.position)}return positions.size();"  
> }  
> }  
> ],  
> "boost\_mode": "replace"  
> }  
> }  
> }
> 
> In the scripting in function\_score , you can access the position and the  
> use this programatically to find the score.  
> I have done an example usage above and it works in the latest version.
> 
> More documentation -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-advanced-scripting.html#_term_positions_offsets_and_payloads)
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)
> 
> Thanks  
> Vineeth
> 
> On Tue, Jul 1, 2014 at 5:59 PM, Dany Gielow \<[dany....@gmail.com](mailto:dany....@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hi Vineeth,
> > 
> > The position is determined by the PositionIncrementAttribute in a Lucene  
> > TokenStream.  
> > So when I say multiple tokens at the same position, I mean tokens that  
> > have a positionIncrement of 0.
> > 
> > These tokens are generated by a SynonymFilter for example, which expands  
> > all synonyms. All these synonyms would have the same position.  
> > In my example "car" and "automobile" are synonyms which are expanded.
> > 
> > On Tuesday, July 1, 2014 2:11:17 PM UTC+2, vineeth mohan wrote:
> > 
> > > Hello Dany ,
> > > 
> > > I didnt really understand what you mean by position.  
> > > Kindly clarify.
> > > 
> > > Thanks  
> > > Vineeth
> > > 
> > > On Tue, Jul 1, 2014 at 5:18 PM, Dany Gielow [dany....@gmail.com](mailto:dany....@gmail.com) wrote:
> > > 
> > > > Hello,
> > > > 
> > > > I want to match only documents which match all positions.  
> > > > My approach would be to index the number of positions and compare it to  
> > > > the number of matched positions.
> > > > 
> > > > Every position that has multiple tokens (stacked tokens) should count  
> > > > only as 1.
> > > > 
> > > > Given the following positions in a field:  
> > > > _Position 1_: red  
> > > > _Position 2_: car, automobile
> > > > 
> > > > These queries should be scored as follows:
> > > > 
> > > > _"red"_: 1  
> > > > _"car"_: 1  
> > > > _"automobile"_: 1  
> > > > _"red car"_: 2  
> > > > _"red automobile"_: 2  
> > > > _"car automobile"_: 1  
> > > > _"fast red car"_: 2
> > > > 
> > > > What approach should I use to get the number of matched positions as a  
> > > > score?  
> > > > I guess I need a custom similarity for that.
> > > > 
> > > > Thanks in advance  
> > > > Dany
> > > > 
> > > > --  
> > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > 
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%  
> > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/df6dcbf4-b542-445d-9b33-05a1a4bd1354%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/df6dcbf4-b542-445d-9b33-05a1a4bd1354%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/df6dcbf4-b542-445d-9b33-05a1a4bd1354%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/df6dcbf4-b542-445d-9b33-05a1a4bd1354%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/dd510e2e-f982-4c4a-aa91-3c139e20927e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/dd510e2e-f982-4c4a-aa91-3c139e20927e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [July 1, 2014, 2:06pm UTC](https://discuss.elastic.co/t/number-of-matched-positions-as-score/18414/6 "2014-07-01T14:06:05Z")

</div>

Hello ,

Exactly , go for a script which will check the position of each term and  
add that to the score if that position is not already taken.

Thanks  
Vineeth

On Tue, Jul 1, 2014 at 7:21 PM, Dany Gielow [dany.gielow@gmail.com](mailto:dany.gielow@gmail.com) wrote:

> Hello Vineeth,
> 
> Your script works like a charm. Thank you very much.
> 
> I will probably write a native script function, which will support  
> multiple query terms.
> 
> Thank you again  
> Dany
> 
> On Tuesday, July 1, 2014 3:27:36 PM UTC+2, vineeth mohan wrote:
> 
> > Hello Dany ,
> > 
> > This is ( surprisingly ) possible.
> > 
> > {  
> > "size": 30,  
> > "from": 0,  
> > "explain": true,  
> > "query": {  
> > "function\_score": {  
> > "query": {  
> > "query\_string": {  
> > "query": "red",  
> > "fields": [  
> > "message"  
> > ]  
> > }  
> > },  
> > "functions": [  
> > {  
> > "script\_score": {  
> > "script": "termInfo = \_index['message'].get('red',\_POSITIONS  
> > | \_CACHE);positions = ;score = 0;for (pos : termInfo) {  
> > if(positions.contains(pos.position)){ ;next;} score = score +  
> > pos.position;positions.add(pos.position)}return positions.size();"  
> > }  
> > }  
> > ],  
> > "boost\_mode": "replace"  
> > }  
> > }  
> > }
> > 
> > In the scripting in function\_score , you can access the position and the  
> > use this programatically to find the score.  
> > I have done an example usage above and it works in the latest version.
> > 
> > More documentation - [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/)  
> > reference/current/modules-advanced-scripting.html#_term_  
> > positions\_offsets\_and\_payloads  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/)  
> > reference/current/query-dsl-function-score-query.html
> > 
> > Thanks  
> > Vineeth
> > 
> > On Tue, Jul 1, 2014 at 5:59 PM, Dany Gielow [dany....@gmail.com](mailto:dany....@gmail.com) wrote:
> > 
> > > Hi Vineeth,
> > > 
> > > The position is determined by the PositionIncrementAttribute in a Lucene  
> > > TokenStream.  
> > > So when I say multiple tokens at the same position, I mean tokens that  
> > > have a positionIncrement of 0.
> > > 
> > > These tokens are generated by a SynonymFilter for example, which expands  
> > > all synonyms. All these synonyms would have the same position.  
> > > In my example "car" and "automobile" are synonyms which are expanded.
> > > 
> > > On Tuesday, July 1, 2014 2:11:17 PM UTC+2, vineeth mohan wrote:
> > > 
> > > > Hello Dany ,
> > > > 
> > > > I didnt really understand what you mean by position.  
> > > > Kindly clarify.
> > > > 
> > > > Thanks  
> > > > Vineeth
> > > > 
> > > > On Tue, Jul 1, 2014 at 5:18 PM, Dany Gielow [dany....@gmail.com](mailto:dany....@gmail.com) wrote:
> > > > 
> > > > > Hello,
> > > > > 
> > > > > I want to match only documents which match all positions.  
> > > > > My approach would be to index the number of positions and compare it  
> > > > > to the number of matched positions.
> > > > > 
> > > > > Every position that has multiple tokens (stacked tokens) should count  
> > > > > only as 1.
> > > > > 
> > > > > Given the following positions in a field:  
> > > > > _Position 1_: red  
> > > > > _Position 2_: car, automobile
> > > > > 
> > > > > These queries should be scored as follows:
> > > > > 
> > > > > _"red"_: 1  
> > > > > _"car"_: 1  
> > > > > _"automobile"_: 1  
> > > > > _"red car"_: 2  
> > > > > _"red automobile"_: 2  
> > > > > _"car automobile"_: 1  
> > > > > _"fast red car"_: 2
> > > > > 
> > > > > What approach should I use to get the number of matched positions as a  
> > > > > score?  
> > > > > I guess I need a custom similarity for that.
> > > > > 
> > > > > Thanks in advance  
> > > > > Dany
> > > > > 
> > > > > --  
> > > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > 
> > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40goo  
> > > > > [glegroups.com](http://glegroups.com)  
> > > > > [https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3d90446e-b1d8-4c8d-8566-d10db7e82369%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > .  
> > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > 
> > > > --  
> > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/df6dcbf4-b542-445d-9b33-05a1a4bd1354%  
> > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/df6dcbf4-b542-445d-9b33-05a1a4bd1354%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/df6dcbf4-b542-445d-9b33-05a1a4bd1354%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .
> > > 
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > 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).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/dd510e2e-f982-4c4a-aa91-3c139e20927e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/dd510e2e-f982-4c4a-aa91-3c139e20927e%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/dd510e2e-f982-4c4a-aa91-3c139e20927e%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/dd510e2e-f982-4c4a-aa91-3c139e20927e%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5%3DNZyre14jERukkJUTJJo\_uKJ1r57EtfxPdy5BoDN%2BG5w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5%3DNZyre14jERukkJUTJJo_uKJ1r57EtfxPdy5BoDN%2BG5w%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:18am UTC](https://discuss.elastic.co/t/number-of-matched-positions-as-score/18414/7 "2017-07-06T01:18:40Z")

</div>


