# Results scoring

**URL:** <https://discuss.elastic.co/t/results-scoring/9456>\
**Category:** Elasticsearch\
**Created:** [October 24, 2012, 7:47am UTC](https://discuss.elastic.co/t/results-scoring/9456 "2012-10-24T07:47:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11111](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/11111/32/2406_2.png) [@11111](https://discuss.elastic.co/u/11111)\
**Post date:** [October 24, 2012, 7:47am UTC](https://discuss.elastic.co/t/results-scoring/9456/1 "2012-10-24T07:47:12Z")

</div>

I'm moving from Sphinx to ES and I can't make ES to score results properly.

_Mapping:_

```
  "properties" : {
    "address" : {
      "type" : "string",
      "boost" : 20.0,
      "analyzer" : "street_analyzer_index",
      "omit_term_freq_and_positions" : true,
      "search_quote_analyzer" : "street_analyzer_search"
    },
    "metro" : {
      "properties" : {
        "name_ru" : {
          "type" : "string",
          "boost" : 10.0,
          "analyzer" : "street_analyzer_index",
          "omit_term_freq_and_positions" : true,
          "search_quote_analyzer" : "street_analyzer_search"
        }
      }
    },
    "name_en" : {
      "type" : "string",
      "boost" : 20.0,
      "analyzer" : "word_analyzer_index",
      "omit_term_freq_and_positions" : true,
      "search_quote_analyzer" : "word_analyzer_search"
    },
    "name_ru" : {
      "type" : "string",
      "boost" : 20.0,
      "index_analyzer" : "word_analyzer_index",
      "search_analyzer" : "word_analyzer_search",
      "omit_term_freq_and_positions" : true
    }

```

_Query_ (just some examples instead of the russian ones):

```
curl -X GET "http://localhost:9200/tomesto_places/place/_search?from=0&page=1&per_page=7&size=7&pretty=true" -d '{"query":{"custom_filters_score":{"query":{"dis_max":{"queries":[{"bool":{"should":[{"text":{"name_en":{"query":"bar 5th avenue","analyzer":"word_analyzer_search","fuzziness":0.8,"operator":"or","boost":20}}},{"text":{"name_en":{"query":"bar 5th avenue","analyzer":"word_analyzer_search","fuzziness":0.8,"operator":"or","boost":20}}},{"text":{"address":{"query":"bar 5th avenue","analyzer":"street_analyzer_search","fuzziness":0.8,"operator":"or","boost":10}}},{"text":{"metro.name_ru":{"query":"bar 5th avenue","analyzer":"street_analyzer_search","fuzziness":0.8,"operator":"or","boost":20}}}]}}]}}}}'

```

_Results:_

Great bar jackson st _(score 43505656000.0 ??!!!)_

awesome bar madelyn road _(score 41732174200.0 ??!!!)_

...

And nothing about "5th avenue"! I'm expecting items with name 'bar bla bla' and address '5th avenue 12' to be scored higher. Queries for just '5th avenue' gets a tiny score of ~4000. What am I doing wrong and how can I get proper results ranking? In same case Sphinx is working out of the box, ranking everything very well in extended match mode.

--

---

<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:** [October 24, 2012, 8:36am UTC](https://discuss.elastic.co/t/results-scoring/9456/2 "2012-10-24T08:36:53Z")

</div>

Hey man,

I don't think your query is doing what you think it is doing. you are  
searching across 3 fields with 3 boolean queries "bar 5th avenue" including  
fuzzyness and without a rewrite method. that means you are actually  
searching with "constant\_score" based on your boost. depending on how many  
terms you match in your text query some scores will shoot out of the roof!  
It's hard to tell why this score came up but if you could provide some  
explain output I could tell you more  
([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/explain.html))

I think I can guess what you are trying to do (yet I'd likely approach it  
differently) but as a short term advice I'd likely add a  
"fuzzy\_rewrite" : "scoring\_boolean" next to your "fuzzieness" : 0.8 to  
check if that helps. I also recommend you to look into "shingle filter" to  
improve your "precision" as an additional query clause.

simon  
On Wednesday, October 24, 2012 9:47:12 AM UTC+2, Кирилл Шнуров wrote:

> I'm moving from Sphinx to ES and I can't make ES to score results properly.
> 
> _Mapping:_
> 
> ```
> "properties" : {
> "address" : {
> "type" : "string",
> "boost" : 20.0,
> "analyzer" : "street_analyzer_index",
> "omit_term_freq_and_positions" : true,
> "search_quote_analyzer" : "street_analyzer_search"
> },
> "metro" : {
> "properties" : {
> "name_ru" : {
> "type" : "string",
> "boost" : 10.0,
> "analyzer" : "street_analyzer_index",
> "omit_term_freq_and_positions" : true,
> "search_quote_analyzer" : "street_analyzer_search"
> }
> }
> },
> "name_en" : {
> "type" : "string",
> "boost" : 20.0,
> "analyzer" : "word_analyzer_index",
> "omit_term_freq_and_positions" : true,
> "search_quote_analyzer" : "word_analyzer_search"
> },
> "name_ru" : {
> "type" : "string",
> "boost" : 20.0,
> "index_analyzer" : "word_analyzer_index",
> "search_analyzer" : "word_analyzer_search",
> "omit_term_freq_and_positions" : true
> }
> 
> ```
> 
> _Query_ (just some examples instead of the russian ones):
> 
> ```
> curl -X GET "http://localhost:9200/tomesto_places/place/_search?from=0&page=1&per_page=7&size=7&pretty=true" -d '{"query":{"custom_filters_score":{"query":{"dis_max":{"queries":[{"bool":{"should":[{"text":{"name_en":{"query":"bar 5th avenue","analyzer":"word_analyzer_search","fuzziness":0.8,"operator":"or","boost":20}}},{"text":{"name_en":{"query":"bar 5th avenue","analyzer":"word_analyzer_search","fuzziness":0.8,"operator":"or","boost":20}}},{"text":{"address":{"query":"bar 5th avenue","analyzer":"street_analyzer_search","fuzziness":0.8,"operator":"or","boost":10}}},{"text":{"metro.name_ru":{"query":"bar 5th avenue","analyzer":"street_analyzer_search","fuzziness":0.8,"operator":"or","boost":20}}}]}}]}}}}'
> 
> ```
> 
> _Results:_
> 
> Great bar jackson st _(score 43505656000.0 ??!!!)_
> 
> awesome bar madelyn road _(score 41732174200.0 ??!!!)_
> 
> ...
> 
> And nothing about "5th avenue"! I'm expecting items with name 'bar bla bla' and address '5th avenue 12' to be scored higher. Queries for just '5th avenue' gets a tiny score of ~4000. What am I doing wrong and how can I get proper results ranking? In same case Sphinx is working out of the box, ranking everything very well in extended match mode.

--

---

<div class="post-metadata">

**Author:** ![11111](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/11111/32/2406_2.png) [@11111](https://discuss.elastic.co/u/11111)\
**Post date:** [October 24, 2012, 9:33am UTC](https://discuss.elastic.co/t/results-scoring/9456/3 "2012-10-24T09:33:32Z")

</div>

Thank's for reply!  
Actually I'm searching through 9 fields, I've truncated the example. Here's  
the full query with explain: [http://gist.github.com/3945005](http://gist.github.com/3945005)  
It gets boosted because of fieldNorm:

```
     "value" : 7.5161928E9,
     "description" : "fieldNorm(field=fields.value, doc=122)"

```

Looks like I'm using ES the wrong way. I'm new with it, so I'll try to  
describe my task:  
When user types something like "\*italian restaurant with wi-fi on 5th avenue  
\*", I want to find document with:  
_address_ (string) - 5th avenue  
_kitchens_ (array of strings) - italian  
_categories_ (array of strings) - restaurant  
_fields.name_ (string) - wi-fi (exists only when wi-fi = true)  
"with" and "on" are already added to stopwords.

In Sphinx it was done by this (Rails&ThinkingSphinx): _Place.search  
'italian restaurant with wi-fi on 5th avenue', :match\_mode =\> :extended_  
But Sphinx uses proximity\_bm25 ranking mode. How can I achieve the same  
result with ES? Searching with text '\_all' gives no results at all.

среда, 24 октября 2012 г., 12:36:54 UTC+4 пользователь simonw написал:

> Hey man,
> 
> I don't think your query is doing what you think it is doing. you are  
> searching across 3 fields with 3 boolean queries "bar 5th avenue" including  
> fuzzyness and without a rewrite method. that means you are actually  
> searching with "constant\_score" based on your boost. depending on how many  
> terms you match in your text query some scores will shoot out of the roof!  
> It's hard to tell why this score came up but if you could provide some  
> explain output I could tell you more (  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/explain.html))
> 
> I think I can guess what you are trying to do (yet I'd likely approach it  
> differently) but as a short term advice I'd likely add a  
> "fuzzy\_rewrite" : "scoring\_boolean" next to your "fuzzieness" : 0.8 to  
> check if that helps. I also recommend you to look into "shingle filter" to  
> improve your "precision" as an additional query clause.
> 
> simon  
> On Wednesday, October 24, 2012 9:47:12 AM UTC+2, Кирилл Шнуров wrote:
> 
> > I'm moving from Sphinx to ES and I can't make ES to score results  
> > properly.
> > 
> > _Mapping:_
> > 
> > ```
> > "properties" : {
> > "address" : {
> > "type" : "string",
> > "boost" : 20.0,
> > "analyzer" : "street_analyzer_index",
> > "omit_term_freq_and_positions" : true,
> > "search_quote_analyzer" : "street_analyzer_search"
> > },
> > "metro" : {
> > "properties" : {
> > "name_ru" : {
> > "type" : "string",
> > "boost" : 10.0,
> > "analyzer" : "street_analyzer_index",
> > "omit_term_freq_and_positions" : true,
> > "search_quote_analyzer" : "street_analyzer_search"
> > }
> > }
> > },
> > "name_en" : {
> > "type" : "string",
> > "boost" : 20.0,
> > "analyzer" : "word_analyzer_index",
> > "omit_term_freq_and_positions" : true,
> > "search_quote_analyzer" : "word_analyzer_search"
> > },
> > "name_ru" : {
> > "type" : "string",
> > "boost" : 20.0,
> > "index_analyzer" : "word_analyzer_index",
> > "search_analyzer" : "word_analyzer_search",
> > "omit_term_freq_and_positions" : true
> > }
> > 
> > ```
> > 
> > _Query_ (just some examples instead of the russian ones):
> > 
> > ```
> > curl -X GET "http://localhost:9200/tomesto_places/place/_search?from=0&page=1&per_page=7&size=7&pretty=true" -d '{"query":{"custom_filters_score":{"query":{"dis_max":{"queries":[{"bool":{"should":[{"text":{"name_en":{"query":"bar 5th avenue","analyzer":"word_analyzer_search","fuzziness":0.8,"operator":"or","boost":20}}},{"text":{"name_en":{"query":"bar 5th avenue","analyzer":"word_analyzer_search","fuzziness":0.8,"operator":"or","boost":20}}},{"text":{"address":{"query":"bar 5th avenue","analyzer":"street_analyzer_search","fuzziness":0.8,"operator":"or","boost":10}}},{"text":{"metro.name_ru":{"query":"bar 5th avenue","analyzer":"street_analyzer_search","fuzziness":0.8,"operator":"or","boost":20}}}]}}]}}}}'
> > 
> > ```
> > 
> > _Results:_
> > 
> > Great bar jackson st _(score 43505656000.0 ??!!!)_
> > 
> > awesome bar madelyn road _(score 41732174200.0 ??!!!)_
> > 
> > ...
> > 
> > And nothing about "5th avenue"! I'm expecting items with name 'bar bla bla' and address '5th avenue 12' to be scored higher. Queries for just '5th avenue' gets a tiny score of ~4000. What am I doing wrong and how can I get proper results ranking? In same case Sphinx is working out of the box, ranking everything very well in extended match mode.

--

---

<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:07am UTC](https://discuss.elastic.co/t/results-scoring/9456/4 "2017-07-06T03:07:26Z")

</div>


