Search code examples
javaelasticsearchelasticsearch-mapping

Why does ElasticSearch is not showing the score?


I am using ElasticSearch 2.3.1 on Ubuntu 16.04.

The mapping is:

{
    "settings": {
        "analysis": {
            "filter": {             
                "2gramsto3_filter": {
                    "type":     "ngram",
                    "min_gram": 2,
                    "max_gram": 3
                }                
            },        
            "analyzer": {
                "2gramsto3": {
                    "type":      "custom",
                    "tokenizer": "standard",
                    "filter":   [
                        "lowercase",
                        "2gramsto3_filter"
                    ]
                }
            }
        }
    },  
    "mappings": {
        "agents": {
            "properties": {                             
                "presentation": {
                    "type": "string",
                    "analyzer": "2gramsto3"                 
                },
                "cv": {
                    "type": "string",
                    "analyzer": "2gramsto3"                 
                }
        }
    }
}

The query is:

{
  "size": 20,
  "from": 0,
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "must": [
              [
                {
                  "match": {
                    "cv": "folletto"
                  }
                },
                {
                  "match": {
                    "cv": " psicologia"
                  }
                },
                {
                  "match": {
                    "cv": " tenacia"
                  }
                }
              ]
            ]
          }
        }
      ]
    }
  }
}

It found 14567 documents but the score is always "_score": 0

I read the filters have the score, so, why not in this case?

Thank you!


Solution

  • The score is not calculated for filters. You need to use a normal query if you need scores.

    Just take into account implications pointed out at the documentation below. Ref doc: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html