nonNumericalFloat
nonNumericalFloat

Reputation: 1787

scoring of Term vs. Terms query different

I am retrieving documents by filtering and using a term query to apply a score. The query should match all animals having a specified color - the more colors are matched, the higher the score of a doc. Strange thing is, term and terms query result in a different scoring.

{
    "query": {
        "bool": {
            "should": [
                {"terms": {"color": ["brown","darkbrown"] } },
            ]
        }
    }
}

should be the same like using

{"term": {"color": {"value": "brown"} } },
{"term": {"color": {"value": "darkbrown"} } }

Query no. 1 gives me the exact same score for a document whether 1 or 2 terms are matched. The latter of course returns a higher score, if more colors are matched.

As stated by the coordination factor the returned score should be higher if more terms are matched. Therefore these two queries should result in the same score - or is because term queries do not analyze the search term?

My field is indexed as text. Strings are indexed as an "array" of strings, e.g. "brown","darkbrown"

Upvotes: 7

Views: 8464

Answers (1)

Umar Hayat
Umar Hayat

Reputation: 4991

Difference between term vs terms query:

  • Term query return documents that contain one or more exact term in a provided field.
  • The terms query is the same as the term query, except you can search for multiple values.
  • Warning: Avoid using the term query for text fields.

As far your this part is concerned

or is because term queries do not analyze the search term?

Yes, It is because the search term does not analyze the term searched. It just matches the exact search term.

Upvotes: 3

Related Questions