Sean's Blog

心之所向,身之所往。

[Elasticsearch] Working with disjunction max query - dis_max

GET /_search
{
  "query": {
    "dis_max": {
      "queries": [
        { "term": { "title": "iphone" } },
        { "term": { "body": "iphone" } }
      ],
      // "tie_breaker": 0.7
    }
  }
}

ㄉ12121221 This is the official document written about dis_max:

Returns documents matching one or more wrapped queries, called query clauses or clauses.

If a returned document matches multiple query clauses, the dis_max query assigns the document the highest relevance score from any matching clause, plus a tie breaking increment for any additional matching subqueries.


[Elasticsearch] How to use minimum_should_match and operator with match query?

GET /_search
{
  "query": {
    "match": {
      "message": {
        "query": "this is a test yo",
        // "operator": "or"
      }
    }
  }
}

This is the Match query we see quite often when using ES. However, if you did specify an analyzer during mapping, the query “this is a test yo" will likely be tokenized into five terms ”this”, “is”, “a”, “test”, and “yo” in the search phases. And there is an implicit parameter operator, and its default value is “or”. This means, this query will look up the documents in the index, and whenever there is any term match in the message of a doc, then that it’s a match!


[Elasticsearch] Function score query

By reading the official document of the Function score query, I still couldn’t get a sense of how to use it correctly. After reading through more articles written by others, here’s how I interpret it with the formula of the newly computed score: function_score = min(score_mode(f1_score, f2_score, ...), max_boost) _score = boost_mode(boost*query_score, function_score) Example 1: { "query": { "function_score": { "query": { "match_all": {} }, "boost": "5", "random_score": {}, "boost_mode": "multiply" } } } Score: