# Score depending on position in the term on the field

**URL:** <https://discuss.elastic.co/t/score-depending-on-position-in-the-term-on-the-field/15357>\
**Category:** Elasticsearch\
**Created:** [January 22, 2014, 12:10pm UTC](https://discuss.elastic.co/t/score-depending-on-position-in-the-term-on-the-field/15357 "2014-01-22T12:10:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikolay\_Chankov](https://avatars.discourse-cdn.com/v4/letter/n/a8b319/32.png) [@Nikolay\_Chankov](https://discuss.elastic.co/u/Nikolay_Chankov)\
**Post date:** [January 22, 2014, 12:10pm UTC](https://discuss.elastic.co/t/score-depending-on-position-in-the-term-on-the-field/15357/1 "2014-01-22T12:10:00Z")

</div>

I am playing with elasticsearch so far, and i noticed something:

If I search for a word in a string, the \_score is equal no matter where is  
placed the word. Here I have prepared a test case:

curl -XDELETE '[http://localhost:9200/test\_search](http://localhost:9200/test_search)'  
curl -XPUT '[http://localhost:9200/test\_search/](http://localhost:9200/test_search/)' -d '  
{  
"mappings" : {  
"test\_record" : {  
"properties" : {  
"name" : {  
"type" : "string"  
}  
}  
}  
}  
}'

curl -XPUT '[http://localhost:9200/test\_search/test\_record/1](http://localhost:9200/test_search/test_record/1)' -d '{  
"name" : "is the name Venue of that one"  
}'

curl -XPUT '[http://localhost:9200/test\_search/test\_record/2](http://localhost:9200/test_search/test_record/2)' -d '{  
"name" : "is the name of that one Venue"  
}'

curl -XPUT '[http://localhost:9200/test\_search/test\_record/3](http://localhost:9200/test_search/test_record/3)' -d '{  
"name" : "Venue is the name of that one"  
}'

curl -XGET '[http://localhost:9200/test\_search/\_search](http://localhost:9200/test_search/_search)' -d '{  
"query": {  
"bool": {  
"must": [],  
"must\_not": [],  
"should": [  
{  
"query\_string" : {  
"default\_field": "\_all",  
"query" : "venue"  
}  
}  
]  
}  
},  
"from": 0,  
"size": 10  
}'

The question is: how to have different score based on the position of the  
word 'venue' in the test. When I search I would expect results to be  
ordered 3,1,2 while now they are as they are inserted ,1,2,3.

Any hint will be much appreciated

--  
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/c69d8a86-f991-4f00-a315-ff56fc075bee%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c69d8a86-f991-4f00-a315-ff56fc075bee%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Johan\_Rask](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johan_rask/32/1132_2.png) [@Johan\_Rask](https://discuss.elastic.co/u/Johan_Rask)\
**Post date:** [January 22, 2014, 9:30pm UTC](https://discuss.elastic.co/t/score-depending-on-position-in-the-term-on-the-field/15357/2 "2014-01-22T21:30:19Z")

</div>

Lucene will calculate you score based on a scoring formula. I am pretty  
sure that the location of the word is not part of this formula but rather  
how common the  
word is in your sentence. I.e multiple occurences of 'venue' should  
increase scoring and adding other words to your sentence should decrease  
the scoring.

Hope this helps, I am pretty sure there is detailed info about this in the  
lucene docs.

Kind regards /Johan

Den onsdagen den 22:e januari 2014 kl. 13:10:00 UTC+1 skrev Nikolay Chankov:

> I am playing with elasticsearch so far, and i noticed something:
> 
> If I search for a word in a string, the \_score is equal no matter where is  
> placed the word. Here I have prepared a test case:
> 
> curl -XDELETE '[http://localhost:9200/test\_search](http://localhost:9200/test_search)'  
> curl -XPUT '[http://localhost:9200/test\_search/](http://localhost:9200/test_search/)' -d '  
> {  
> "mappings" : {  
> "test\_record" : {  
> "properties" : {  
> "name" : {  
> "type" : "string"  
> }  
> }  
> }  
> }  
> }'
> 
> curl -XPUT '[http://localhost:9200/test\_search/test\_record/1](http://localhost:9200/test_search/test_record/1)' -d '{  
> "name" : "is the name Venue of that one"  
> }'
> 
> curl -XPUT '[http://localhost:9200/test\_search/test\_record/2](http://localhost:9200/test_search/test_record/2)' -d '{  
> "name" : "is the name of that one Venue"  
> }'
> 
> curl -XPUT '[http://localhost:9200/test\_search/test\_record/3](http://localhost:9200/test_search/test_record/3)' -d '{  
> "name" : "Venue is the name of that one"  
> }'
> 
> curl -XGET '[http://localhost:9200/test\_search/\_search](http://localhost:9200/test_search/_search)' -d '{  
> "query": {  
> "bool": {  
> "must": ,  
> "must\_not": ,  
> "should": [  
> {  
> "query\_string" : {  
> "default\_field": "\_all",  
> "query" : "venue"  
> }  
> }  
> ]  
> }  
> },  
> "from": 0,  
> "size": 10  
> }'
> 
> The question is: how to have different score based on the position of the  
> word 'venue' in the test. When I search I would expect results to be  
> ordered 3,1,2 while now they are as they are inserted ,1,2,3.
> 
> Any hint will be much appreciated

--  
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/2e9ae53d-0bb3-4d56-93b2-f62c95fe93fb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2e9ae53d-0bb3-4d56-93b2-f62c95fe93fb%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Nikolay\_Chankov](https://avatars.discourse-cdn.com/v4/letter/n/a8b319/32.png) [@Nikolay\_Chankov](https://discuss.elastic.co/u/Nikolay_Chankov)\
**Post date:** [January 23, 2014, 8:44am UTC](https://discuss.elastic.co/t/score-depending-on-position-in-the-term-on-the-field/15357/3 "2014-01-23T08:44:02Z")

</div>

Hi Johan,

thanks for the reply

I would agree that it's ok, if I am searching for common term, like  
'venue', 'club' or 'bar', but when it comes to User names, it make sense to  
score the position in the field too, because when you search in field  
user.name, and type 'Jo' you would expect first to see users with first  
name Joe, Johan, John, rather than having users with Jo in the family.

And especially when you search for user name field you don't expect to have  
more occurrence of the name in that field.

On Wednesday, January 22, 2014 9:30:19 PM UTC, Johan Rask wrote:

> Lucene will calculate you score based on a scoring formula. I am pretty  
> sure that the location of the word is not part of this formula but rather  
> how common the  
> word is in your sentence. I.e multiple occurences of 'venue' should  
> increase scoring and adding other words to your sentence should decrease  
> the scoring.
> 
> Hope this helps, I am pretty sure there is detailed info about this in the  
> lucene docs.
> 
> Kind regards /Johan
> 
> Den onsdagen den 22:e januari 2014 kl. 13:10:00 UTC+1 skrev Nikolay  
> Chankov:
> 
> > I am playing with elasticsearch so far, and i noticed something:
> > 
> > If I search for a word in a string, the \_score is equal no matter where  
> > is placed the word. Here I have prepared a test case:
> > 
> > curl -XDELETE '[http://localhost:9200/test\_search](http://localhost:9200/test_search)'  
> > curl -XPUT '[http://localhost:9200/test\_search/](http://localhost:9200/test_search/)' -d '  
> > {  
> > "mappings" : {  
> > "test\_record" : {  
> > "properties" : {  
> > "name" : {  
> > "type" : "string"  
> > }  
> > }  
> > }  
> > }  
> > }'
> > 
> > curl -XPUT '[http://localhost:9200/test\_search/test\_record/1](http://localhost:9200/test_search/test_record/1)' -d '{  
> > "name" : "is the name Venue of that one"  
> > }'
> > 
> > curl -XPUT '[http://localhost:9200/test\_search/test\_record/2](http://localhost:9200/test_search/test_record/2)' -d '{  
> > "name" : "is the name of that one Venue"  
> > }'
> > 
> > curl -XPUT '[http://localhost:9200/test\_search/test\_record/3](http://localhost:9200/test_search/test_record/3)' -d '{  
> > "name" : "Venue is the name of that one"  
> > }'
> > 
> > curl -XGET '[http://localhost:9200/test\_search/\_search](http://localhost:9200/test_search/_search)' -d '{  
> > "query": {  
> > "bool": {  
> > "must": ,  
> > "must\_not": ,  
> > "should": [  
> > {  
> > "query\_string" : {  
> > "default\_field": "\_all",  
> > "query" : "venue"  
> > }  
> > }  
> > ]  
> > }  
> > },  
> > "from": 0,  
> > "size": 10  
> > }'
> > 
> > The question is: how to have different score based on the position of the  
> > word 'venue' in the test. When I search I would expect results to be  
> > ordered 3,1,2 while now they are as they are inserted ,1,2,3.
> > 
> > Any hint will be much appreciated

--  
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/d2d79908-0131-4220-941c-eb31e51b9667%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d2d79908-0131-4220-941c-eb31e51b9667%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Johan\_Rask](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johan_rask/32/1132_2.png) [@Johan\_Rask](https://discuss.elastic.co/u/Johan_Rask)\
**Post date:** [January 23, 2014, 9:36am UTC](https://discuss.elastic.co/t/score-depending-on-position-in-the-term-on-the-field/15357/4 "2014-01-23T09:36:47Z")

</div>

Hi again,

Can you explain more what you are trying to accomplish?

I "think" that the only way you can solve this is to split into multiple  
fields and  
then boost individual fields in your query. Not sure if thats possible for  
you.

/Johan

Den torsdagen den 23:e januari 2014 kl. 09:44:02 UTC+1 skrev Nikolay  
Chankov:

> Hi Johan,
> 
> thanks for the reply
> 
> I would agree that it's ok, if I am searching for common term, like  
> 'venue', 'club' or 'bar', but when it comes to User names, it make sense to  
> score the position in the field too, because when you search in field  
> user.name, and type 'Jo' you would expect first to see users with first  
> name Joe, Johan, John, rather than having users with Jo in the family.
> 
> And especially when you search for user name field you don't expect to  
> have more occurrence of the name in that field.
> 
> On Wednesday, January 22, 2014 9:30:19 PM UTC, Johan Rask wrote:
> 
> > Lucene will calculate you score based on a scoring formula. I am pretty  
> > sure that the location of the word is not part of this formula but rather  
> > how common the  
> > word is in your sentence. I.e multiple occurences of 'venue' should  
> > increase scoring and adding other words to your sentence should decrease  
> > the scoring.
> > 
> > Hope this helps, I am pretty sure there is detailed info about this in  
> > the lucene docs.
> > 
> > Kind regards /Johan
> > 
> > Den onsdagen den 22:e januari 2014 kl. 13:10:00 UTC+1 skrev Nikolay  
> > Chankov:
> > 
> > > I am playing with elasticsearch so far, and i noticed something:
> > > 
> > > If I search for a word in a string, the \_score is equal no matter where  
> > > is placed the word. Here I have prepared a test case:
> > > 
> > > curl -XDELETE '[http://localhost:9200/test\_search](http://localhost:9200/test_search)'  
> > > curl -XPUT '[http://localhost:9200/test\_search/](http://localhost:9200/test_search/)' -d '  
> > > {  
> > > "mappings" : {  
> > > "test\_record" : {  
> > > "properties" : {  
> > > "name" : {  
> > > "type" : "string"  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }'
> > > 
> > > curl -XPUT '[http://localhost:9200/test\_search/test\_record/1](http://localhost:9200/test_search/test_record/1)' -d '{  
> > > "name" : "is the name Venue of that one"  
> > > }'
> > > 
> > > curl -XPUT '[http://localhost:9200/test\_search/test\_record/2](http://localhost:9200/test_search/test_record/2)' -d '{  
> > > "name" : "is the name of that one Venue"  
> > > }'
> > > 
> > > curl -XPUT '[http://localhost:9200/test\_search/test\_record/3](http://localhost:9200/test_search/test_record/3)' -d '{  
> > > "name" : "Venue is the name of that one"  
> > > }'
> > > 
> > > curl -XGET '[http://localhost:9200/test\_search/\_search](http://localhost:9200/test_search/_search)' -d '{  
> > > "query": {  
> > > "bool": {  
> > > "must": ,  
> > > "must\_not": ,  
> > > "should": [  
> > > {  
> > > "query\_string" : {  
> > > "default\_field": "\_all",  
> > > "query" : "venue"  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > },  
> > > "from": 0,  
> > > "size": 10  
> > > }'
> > > 
> > > The question is: how to have different score based on the position of  
> > > the word 'venue' in the test. When I search I would expect results to be  
> > > ordered 3,1,2 while now they are as they are inserted ,1,2,3.
> > > 
> > > Any hint will be much appreciated

--  
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/7d7a5a5d-cc7f-4035-b5fb-a558cd71559f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7d7a5a5d-cc7f-4035-b5fb-a558cd71559f%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Nikolay\_Chankov](https://avatars.discourse-cdn.com/v4/letter/n/a8b319/32.png) [@Nikolay\_Chankov](https://discuss.elastic.co/u/Nikolay_Chankov)\
**Post date:** [January 23, 2014, 10:08am UTC](https://discuss.elastic.co/t/score-depending-on-position-in-the-term-on-the-field/15357/5 "2014-01-23T10:08:25Z")

</div>

Hi Johan,

I've already saw this suggestion, but it's not really useful for me, since  
in the index there are various document with different types. For example,  
I have users, but also I have venues and events, last two had only name,  
while user could have two names.

In general I am trying to build an autosuggest feature on a site and when  
you start typing 'Joh' the suggestions will be first users starting with  
'Joh', but there could be some venues starting with 'Joh' string as well,  
so as much you type, the more concrete results you will have, but I am also  
reading about suggesters, and probably I will implement a solution which  
will be more like Google autosuggest rather displaying the first few  
results of the search itself.

I've seen also text scoring in scripts[http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-advanced-scripting.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-advanced-scripting.html) which  
could be a solution as well.

I just wanted to ask if there is something like common way of score the  
position of the term in a field, but obviously there is no such way. 🙂

Thanks for the help

On Thursday, January 23, 2014 9:36:47 AM UTC, Johan Rask wrote:

> Hi again,
> 
> Can you explain more what you are trying to accomplish?
> 
> I "think" that the only way you can solve this is to split into multiple  
> fields and  
> then boost individual fields in your query. Not sure if thats possible for  
> you.
> 
> /Johan
> 
> Den torsdagen den 23:e januari 2014 kl. 09:44:02 UTC+1 skrev Nikolay  
> Chankov:
> 
> > Hi Johan,
> > 
> > thanks for the reply
> > 
> > I would agree that it's ok, if I am searching for common term, like  
> > 'venue', 'club' or 'bar', but when it comes to User names, it make sense to  
> > score the position in the field too, because when you search in field  
> > user.name, and type 'Jo' you would expect first to see users with first  
> > name Joe, Johan, John, rather than having users with Jo in the family.
> > 
> > And especially when you search for user name field you don't expect to  
> > have more occurrence of the name in that field.
> > 
> > On Wednesday, January 22, 2014 9:30:19 PM UTC, Johan Rask wrote:
> > 
> > > Lucene will calculate you score based on a scoring formula. I am pretty  
> > > sure that the location of the word is not part of this formula but rather  
> > > how common the  
> > > word is in your sentence. I.e multiple occurences of 'venue' should  
> > > increase scoring and adding other words to your sentence should decrease  
> > > the scoring.
> > > 
> > > Hope this helps, I am pretty sure there is detailed info about this in  
> > > the lucene docs.
> > > 
> > > Kind regards /Johan
> > > 
> > > Den onsdagen den 22:e januari 2014 kl. 13:10:00 UTC+1 skrev Nikolay  
> > > Chankov:
> > > 
> > > > I am playing with elasticsearch so far, and i noticed something:
> > > > 
> > > > If I search for a word in a string, the \_score is equal no matter where  
> > > > is placed the word. Here I have prepared a test case:
> > > > 
> > > > curl -XDELETE '[http://localhost:9200/test\_search](http://localhost:9200/test_search)'  
> > > > curl -XPUT '[http://localhost:9200/test\_search/](http://localhost:9200/test_search/)' -d '  
> > > > {  
> > > > "mappings" : {  
> > > > "test\_record" : {  
> > > > "properties" : {  
> > > > "name" : {  
> > > > "type" : "string"  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }'
> > > > 
> > > > curl -XPUT '[http://localhost:9200/test\_search/test\_record/1](http://localhost:9200/test_search/test_record/1)' -d '{  
> > > > "name" : "is the name Venue of that one"  
> > > > }'
> > > > 
> > > > curl -XPUT '[http://localhost:9200/test\_search/test\_record/2](http://localhost:9200/test_search/test_record/2)' -d '{  
> > > > "name" : "is the name of that one Venue"  
> > > > }'
> > > > 
> > > > curl -XPUT '[http://localhost:9200/test\_search/test\_record/3](http://localhost:9200/test_search/test_record/3)' -d '{  
> > > > "name" : "Venue is the name of that one"  
> > > > }'
> > > > 
> > > > curl -XGET '[http://localhost:9200/test\_search/\_search](http://localhost:9200/test_search/_search)' -d '{  
> > > > "query": {  
> > > > "bool": {  
> > > > "must": ,  
> > > > "must\_not": ,  
> > > > "should": [  
> > > > {  
> > > > "query\_string" : {  
> > > > "default\_field": "\_all",  
> > > > "query" : "venue"  
> > > > }  
> > > > }  
> > > > ]  
> > > > }  
> > > > },  
> > > > "from": 0,  
> > > > "size": 10  
> > > > }'
> > > > 
> > > > The question is: how to have different score based on the position of  
> > > > the word 'venue' in the test. When I search I would expect results to be  
> > > > ordered 3,1,2 while now they are as they are inserted ,1,2,3.
> > > > 
> > > > Any hint will be much appreciated

--  
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/6c5871a3-7421-4626-86c6-ca92afce3534%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6c5871a3-7421-4626-86c6-ca92afce3534%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Nikolay\_Chankov](https://avatars.discourse-cdn.com/v4/letter/n/a8b319/32.png) [@Nikolay\_Chankov](https://discuss.elastic.co/u/Nikolay_Chankov)\
**Post date:** [January 23, 2014, 10:56am UTC](https://discuss.elastic.co/t/score-depending-on-position-in-the-term-on-the-field/15357/6 "2014-01-23T10:56:30Z")

</div>

Just checked the Facebook suggestion style and I would imagine something  
like, this, When you start typing terms which start with the phrase/word  
are in the top, while the terms which just contain the phrase/word, are at  
the bottom. But I could be wrong that that the order is this way 🙂

On Thursday, January 23, 2014 10:08:25 AM UTC, Nikolay Chankov wrote:

> Hi Johan,
> 
> I've already saw this suggestion, but it's not really useful for me, since  
> in the index there are various document with different types. For example,  
> I have users, but also I have venues and events, last two had only name,  
> while user could have two names.
> 
> In general I am trying to build an autosuggest feature on a site and when  
> you start typing 'Joh' the suggestions will be first users starting with  
> 'Joh', but there could be some venues starting with 'Joh' string as well,  
> so as much you type, the more concrete results you will have, but I am also  
> reading about suggesters, and probably I will implement a solution which  
> will be more like Google autosuggest rather displaying the first few  
> results of the search itself.
> 
> I've seen also text scoring in scripts[http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-advanced-scripting.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-advanced-scripting.html) which  
> could be a solution as well.
> 
> I just wanted to ask if there is something like common way of score the  
> position of the term in a field, but obviously there is no such way. 🙂
> 
> Thanks for the help
> 
> On Thursday, January 23, 2014 9:36:47 AM UTC, Johan Rask wrote:
> 
> > Hi again,
> > 
> > Can you explain more what you are trying to accomplish?
> > 
> > I "think" that the only way you can solve this is to split into multiple  
> > fields and  
> > then boost individual fields in your query. Not sure if thats possible  
> > for you.
> > 
> > /Johan
> > 
> > Den torsdagen den 23:e januari 2014 kl. 09:44:02 UTC+1 skrev Nikolay  
> > Chankov:
> > 
> > > Hi Johan,
> > > 
> > > thanks for the reply
> > > 
> > > I would agree that it's ok, if I am searching for common term, like  
> > > 'venue', 'club' or 'bar', but when it comes to User names, it make sense to  
> > > score the position in the field too, because when you search in field  
> > > user.name, and type 'Jo' you would expect first to see users with first  
> > > name Joe, Johan, John, rather than having users with Jo in the family.
> > > 
> > > And especially when you search for user name field you don't expect to  
> > > have more occurrence of the name in that field.
> > > 
> > > On Wednesday, January 22, 2014 9:30:19 PM UTC, Johan Rask wrote:
> > > 
> > > > Lucene will calculate you score based on a scoring formula. I am pretty  
> > > > sure that the location of the word is not part of this formula but rather  
> > > > how common the  
> > > > word is in your sentence. I.e multiple occurences of 'venue' should  
> > > > increase scoring and adding other words to your sentence should decrease  
> > > > the scoring.
> > > > 
> > > > Hope this helps, I am pretty sure there is detailed info about this in  
> > > > the lucene docs.
> > > > 
> > > > Kind regards /Johan
> > > > 
> > > > Den onsdagen den 22:e januari 2014 kl. 13:10:00 UTC+1 skrev Nikolay  
> > > > Chankov:
> > > > 
> > > > > I am playing with elasticsearch so far, and i noticed something:
> > > > > 
> > > > > If I search for a word in a string, the \_score is equal no matter  
> > > > > where is placed the word. Here I have prepared a test case:
> > > > > 
> > > > > curl -XDELETE '[http://localhost:9200/test\_search](http://localhost:9200/test_search)'  
> > > > > curl -XPUT '[http://localhost:9200/test\_search/](http://localhost:9200/test_search/)' -d '  
> > > > > {  
> > > > > "mappings" : {  
> > > > > "test\_record" : {  
> > > > > "properties" : {  
> > > > > "name" : {  
> > > > > "type" : "string"  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }'
> > > > > 
> > > > > curl -XPUT '[http://localhost:9200/test\_search/test\_record/1](http://localhost:9200/test_search/test_record/1)' -d '{  
> > > > > "name" : "is the name Venue of that one"  
> > > > > }'
> > > > > 
> > > > > curl -XPUT '[http://localhost:9200/test\_search/test\_record/2](http://localhost:9200/test_search/test_record/2)' -d '{  
> > > > > "name" : "is the name of that one Venue"  
> > > > > }'
> > > > > 
> > > > > curl -XPUT '[http://localhost:9200/test\_search/test\_record/3](http://localhost:9200/test_search/test_record/3)' -d '{  
> > > > > "name" : "Venue is the name of that one"  
> > > > > }'
> > > > > 
> > > > > curl -XGET '[http://localhost:9200/test\_search/\_search](http://localhost:9200/test_search/_search)' -d '{  
> > > > > "query": {  
> > > > > "bool": {  
> > > > > "must": ,  
> > > > > "must\_not": ,  
> > > > > "should": [  
> > > > > {  
> > > > > "query\_string" : {  
> > > > > "default\_field": "\_all",  
> > > > > "query" : "venue"  
> > > > > }  
> > > > > }  
> > > > > ]  
> > > > > }  
> > > > > },  
> > > > > "from": 0,  
> > > > > "size": 10  
> > > > > }'
> > > > > 
> > > > > The question is: how to have different score based on the position of  
> > > > > the word 'venue' in the test. When I search I would expect results to be  
> > > > > ordered 3,1,2 while now they are as they are inserted ,1,2,3.
> > > > > 
> > > > > Any hint will be much appreciated

--  
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/2f1ea0ed-a0f8-4b38-b483-3b223d4a2899%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2f1ea0ed-a0f8-4b38-b483-3b223d4a2899%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Nikolay\_Chankov](https://avatars.discourse-cdn.com/v4/letter/n/a8b319/32.png) [@Nikolay\_Chankov](https://discuss.elastic.co/u/Nikolay_Chankov)\
**Post date:** [January 23, 2014, 3:15pm UTC](https://discuss.elastic.co/t/score-depending-on-position-in-the-term-on-the-field/15357/7 "2014-01-23T15:15:05Z")

</div>

Well, it's really strange, that position is not encountered, since with  
many results and especially data with lot of similarities (user names)  
doesn't get sorted also by string position somehow.

Anyone to share how do they make autocomplete? Feeling really stupid ☹

On Thursday, January 23, 2014 10:56:30 AM UTC, Nikolay Chankov wrote:

> Just checked the Facebook suggestion style and I would imagine something  
> like, this, When you start typing terms which start with the phrase/word  
> are in the top, while the terms which just contain the phrase/word, are at  
> the bottom. But I could be wrong that that the order is this way 🙂
> 
> On Thursday, January 23, 2014 10:08:25 AM UTC, Nikolay Chankov wrote:
> 
> > Hi Johan,
> > 
> > I've already saw this suggestion, but it's not really useful for me,  
> > since in the index there are various document with different types. For  
> > example, I have users, but also I have venues and events, last two had only  
> > name, while user could have two names.
> > 
> > In general I am trying to build an autosuggest feature on a site and when  
> > you start typing 'Joh' the suggestions will be first users starting with  
> > 'Joh', but there could be some venues starting with 'Joh' string as well,  
> > so as much you type, the more concrete results you will have, but I am also  
> > reading about suggesters, and probably I will implement a solution which  
> > will be more like Google autosuggest rather displaying the first few  
> > results of the search itself.
> > 
> > I've seen also text scoring in scripts[http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-advanced-scripting.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-advanced-scripting.html) which  
> > could be a solution as well.
> > 
> > I just wanted to ask if there is something like common way of score the  
> > position of the term in a field, but obviously there is no such way. 🙂
> > 
> > Thanks for the help
> > 
> > On Thursday, January 23, 2014 9:36:47 AM UTC, Johan Rask wrote:
> > 
> > > Hi again,
> > > 
> > > Can you explain more what you are trying to accomplish?
> > > 
> > > I "think" that the only way you can solve this is to split into multiple  
> > > fields and  
> > > then boost individual fields in your query. Not sure if thats possible  
> > > for you.
> > > 
> > > /Johan
> > > 
> > > Den torsdagen den 23:e januari 2014 kl. 09:44:02 UTC+1 skrev Nikolay  
> > > Chankov:
> > > 
> > > > Hi Johan,
> > > > 
> > > > thanks for the reply
> > > > 
> > > > I would agree that it's ok, if I am searching for common term, like  
> > > > 'venue', 'club' or 'bar', but when it comes to User names, it make sense to  
> > > > score the position in the field too, because when you search in field  
> > > > user.name, and type 'Jo' you would expect first to see users with  
> > > > first name Joe, Johan, John, rather than having users with Jo in the family.
> > > > 
> > > > And especially when you search for user name field you don't expect to  
> > > > have more occurrence of the name in that field.
> > > > 
> > > > On Wednesday, January 22, 2014 9:30:19 PM UTC, Johan Rask wrote:
> > > > 
> > > > > Lucene will calculate you score based on a scoring formula. I am  
> > > > > pretty sure that the location of the word is not part of this formula but  
> > > > > rather how common the  
> > > > > word is in your sentence. I.e multiple occurences of 'venue' should  
> > > > > increase scoring and adding other words to your sentence should decrease  
> > > > > the scoring.
> > > > > 
> > > > > Hope this helps, I am pretty sure there is detailed info about this in  
> > > > > the lucene docs.
> > > > > 
> > > > > Kind regards /Johan
> > > > > 
> > > > > Den onsdagen den 22:e januari 2014 kl. 13:10:00 UTC+1 skrev Nikolay  
> > > > > Chankov:
> > > > > 
> > > > > > I am playing with elasticsearch so far, and i noticed something:
> > > > > > 
> > > > > > If I search for a word in a string, the \_score is equal no matter  
> > > > > > where is placed the word. Here I have prepared a test case:
> > > > > > 
> > > > > > curl -XDELETE '[http://localhost:9200/test\_search](http://localhost:9200/test_search)'  
> > > > > > curl -XPUT '[http://localhost:9200/test\_search/](http://localhost:9200/test_search/)' -d '  
> > > > > > {  
> > > > > > "mappings" : {  
> > > > > > "test\_record" : {  
> > > > > > "properties" : {  
> > > > > > "name" : {  
> > > > > > "type" : "string"  
> > > > > > }  
> > > > > > }  
> > > > > > }  
> > > > > > }  
> > > > > > }'
> > > > > > 
> > > > > > curl -XPUT '[http://localhost:9200/test\_search/test\_record/1](http://localhost:9200/test_search/test_record/1)' -d '{  
> > > > > > "name" : "is the name Venue of that one"  
> > > > > > }'
> > > > > > 
> > > > > > curl -XPUT '[http://localhost:9200/test\_search/test\_record/2](http://localhost:9200/test_search/test_record/2)' -d '{  
> > > > > > "name" : "is the name of that one Venue"  
> > > > > > }'
> > > > > > 
> > > > > > curl -XPUT '[http://localhost:9200/test\_search/test\_record/3](http://localhost:9200/test_search/test_record/3)' -d '{  
> > > > > > "name" : "Venue is the name of that one"  
> > > > > > }'
> > > > > > 
> > > > > > curl -XGET '[http://localhost:9200/test\_search/\_search](http://localhost:9200/test_search/_search)' -d '{  
> > > > > > "query": {  
> > > > > > "bool": {  
> > > > > > "must": ,  
> > > > > > "must\_not": ,  
> > > > > > "should": [  
> > > > > > {  
> > > > > > "query\_string" : {  
> > > > > > "default\_field": "\_all",  
> > > > > > "query" : "venue"  
> > > > > > }  
> > > > > > }  
> > > > > > ]  
> > > > > > }  
> > > > > > },  
> > > > > > "from": 0,  
> > > > > > "size": 10  
> > > > > > }'
> > > > > > 
> > > > > > The question is: how to have different score based on the position of  
> > > > > > the word 'venue' in the test. When I search I would expect results to be  
> > > > > > ordered 3,1,2 while now they are as they are inserted ,1,2,3.
> > > > > > 
> > > > > > Any hint will be much appreciated

--  
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/d4632bdc-c200-4322-a0d2-574e629f2206%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d4632bdc-c200-4322-a0d2-574e629f2206%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [January 24, 2014, 6:14pm UTC](https://discuss.elastic.co/t/score-depending-on-position-in-the-term-on-the-field/15357/8 "2014-01-24T18:14:34Z")

</div>

maybe this is interesting in your situation?

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

simon

On Thursday, January 23, 2014 4:15:05 PM UTC+1, Nikolay Chankov wrote:

> Well, it's really strange, that position is not encountered, since with  
> many results and especially data with lot of similarities (user names)  
> doesn't get sorted also by string position somehow.
> 
> Anyone to share how do they make autocomplete? Feeling really stupid ☹
> 
> On Thursday, January 23, 2014 10:56:30 AM UTC, Nikolay Chankov wrote:
> 
> > Just checked the Facebook suggestion style and I would imagine something  
> > like, this, When you start typing terms which start with the phrase/word  
> > are in the top, while the terms which just contain the phrase/word, are at  
> > the bottom. But I could be wrong that that the order is this way 🙂
> > 
> > On Thursday, January 23, 2014 10:08:25 AM UTC, Nikolay Chankov wrote:
> > 
> > > Hi Johan,
> > > 
> > > I've already saw this suggestion, but it's not really useful for me,  
> > > since in the index there are various document with different types. For  
> > > example, I have users, but also I have venues and events, last two had only  
> > > name, while user could have two names.
> > > 
> > > In general I am trying to build an autosuggest feature on a site and  
> > > when you start typing 'Joh' the suggestions will be first users starting  
> > > with 'Joh', but there could be some venues starting with 'Joh' string as  
> > > well, so as much you type, the more concrete results you will have, but I  
> > > am also reading about suggesters, and probably I will implement a solution  
> > > which will be more like Google autosuggest rather displaying the first few  
> > > results of the search itself.
> > > 
> > > I've seen also text scoring in scripts[http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-advanced-scripting.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-advanced-scripting.html) which  
> > > could be a solution as well.
> > > 
> > > I just wanted to ask if there is something like common way of score the  
> > > position of the term in a field, but obviously there is no such way. 🙂
> > > 
> > > Thanks for the help
> > > 
> > > On Thursday, January 23, 2014 9:36:47 AM UTC, Johan Rask wrote:
> > > 
> > > > Hi again,
> > > > 
> > > > Can you explain more what you are trying to accomplish?
> > > > 
> > > > I "think" that the only way you can solve this is to split into  
> > > > multiple fields and  
> > > > then boost individual fields in your query. Not sure if thats possible  
> > > > for you.
> > > > 
> > > > /Johan
> > > > 
> > > > Den torsdagen den 23:e januari 2014 kl. 09:44:02 UTC+1 skrev Nikolay  
> > > > Chankov:
> > > > 
> > > > > Hi Johan,
> > > > > 
> > > > > thanks for the reply
> > > > > 
> > > > > I would agree that it's ok, if I am searching for common term, like  
> > > > > 'venue', 'club' or 'bar', but when it comes to User names, it make sense to  
> > > > > score the position in the field too, because when you search in field  
> > > > > user.name, and type 'Jo' you would expect first to see users with  
> > > > > first name Joe, Johan, John, rather than having users with Jo in the family.
> > > > > 
> > > > > And especially when you search for user name field you don't expect to  
> > > > > have more occurrence of the name in that field.
> > > > > 
> > > > > On Wednesday, January 22, 2014 9:30:19 PM UTC, Johan Rask wrote:
> > > > > 
> > > > > > Lucene will calculate you score based on a scoring formula. I am  
> > > > > > pretty sure that the location of the word is not part of this formula but  
> > > > > > rather how common the  
> > > > > > word is in your sentence. I.e multiple occurences of 'venue' should  
> > > > > > increase scoring and adding other words to your sentence should decrease  
> > > > > > the scoring.
> > > > > > 
> > > > > > Hope this helps, I am pretty sure there is detailed info about this  
> > > > > > in the lucene docs.
> > > > > > 
> > > > > > Kind regards /Johan
> > > > > > 
> > > > > > Den onsdagen den 22:e januari 2014 kl. 13:10:00 UTC+1 skrev Nikolay  
> > > > > > Chankov:
> > > > > > 
> > > > > > > I am playing with elasticsearch so far, and i noticed something:
> > > > > > > 
> > > > > > > If I search for a word in a string, the \_score is equal no matter  
> > > > > > > where is placed the word. Here I have prepared a test case:
> > > > > > > 
> > > > > > > curl -XDELETE '[http://localhost:9200/test\_search](http://localhost:9200/test_search)'  
> > > > > > > curl -XPUT '[http://localhost:9200/test\_search/](http://localhost:9200/test_search/)' -d '  
> > > > > > > {  
> > > > > > > "mappings" : {  
> > > > > > > "test\_record" : {  
> > > > > > > "properties" : {  
> > > > > > > "name" : {  
> > > > > > > "type" : "string"  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }'
> > > > > > > 
> > > > > > > curl -XPUT '[http://localhost:9200/test\_search/test\_record/1](http://localhost:9200/test_search/test_record/1)' -d '{  
> > > > > > > "name" : "is the name Venue of that one"  
> > > > > > > }'
> > > > > > > 
> > > > > > > curl -XPUT '[http://localhost:9200/test\_search/test\_record/2](http://localhost:9200/test_search/test_record/2)' -d '{  
> > > > > > > "name" : "is the name of that one Venue"  
> > > > > > > }'
> > > > > > > 
> > > > > > > curl -XPUT '[http://localhost:9200/test\_search/test\_record/3](http://localhost:9200/test_search/test_record/3)' -d '{  
> > > > > > > "name" : "Venue is the name of that one"  
> > > > > > > }'
> > > > > > > 
> > > > > > > curl -XGET '[http://localhost:9200/test\_search/\_search](http://localhost:9200/test_search/_search)' -d '{  
> > > > > > > "query": {  
> > > > > > > "bool": {  
> > > > > > > "must": ,  
> > > > > > > "must\_not": ,  
> > > > > > > "should": [  
> > > > > > > {  
> > > > > > > "query\_string" : {  
> > > > > > > "default\_field": "\_all",  
> > > > > > > "query" : "venue"  
> > > > > > > }  
> > > > > > > }  
> > > > > > > ]  
> > > > > > > }  
> > > > > > > },  
> > > > > > > "from": 0,  
> > > > > > > "size": 10  
> > > > > > > }'
> > > > > > > 
> > > > > > > The question is: how to have different score based on the position  
> > > > > > > of the word 'venue' in the test. When I search I would expect results to be  
> > > > > > > ordered 3,1,2 while now they are as they are inserted ,1,2,3.
> > > > > > > 
> > > > > > > Any hint will be much appreciated

--  
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/8cb8fd26-cc4d-4f26-a7cb-b7c6ef5048dc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8cb8fd26-cc4d-4f26-a7cb-b7c6ef5048dc%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:54am UTC](https://discuss.elastic.co/t/score-depending-on-position-in-the-term-on-the-field/15357/9 "2017-07-06T01:54:54Z")

</div>


