Min_score for a "must" in a bool query in Elasticsearch

kiml42

Is there a way to apply a minimum score to a must clause in a bool query in elasticsearch.

I want to be able to do something like this:

{
  "query": {
     "bool": {
        "must": [
            {
              "match": {
                 "name": {
                    "query":"A Name",
                    "min_score": 0.3
                 }
               }
            },
            {
              "match": {
                 "address": {
                    "query":"1 Somewhere Street, Somewhereset, UK",
                    "min_score": 0.3
                 }
               }
            }
        ]
    }
  }
}

Which would require the name query to match with a score > 0.3 and the address query to match with a score > 0.3 for the document to be returned. This is to stop really good name matches being returned despite having a terrible address match (e.g. just matching the 1) and vice versa.

I'm currently using Elasticsearch 1.5, but I've also wanted this in the past for 2.3.

Andrei Stefan

Try this and let me know if it works:

{
  "query": {
    "bool": {
      "must": [
        {
          "function_score": {
            "query": {
              "match": {
                "name": {
                  "query": "A Name"
                }
              }
            },
            "min_score": 0.3
          }
        },
        {
          "function_score": {
            "query": {
              "match": {
                "address": {
                  "query": "1 Somewhere Street, Somewhereset, UK"
                }
              }
            },
            "min_score": 0.3
          }
        }
      ]
    }
  }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Min_score for a "must" in a bool query in Elasticsearch

From Java

elasticsearch bool query combine must with OR

From Java

Elasticsearch difference between MUST and SHOULD bool query

From Dev

Why not use min_score with Elasticsearch?

From Dev

Using bool must match and match _all in one elasticsearch query

From Dev

Elasticsearch bool query with filter

From Dev

Elasticsearch Bool query

From Dev

ElasticSearch bool query request

From Dev

elasticsearch must query combine OR?

From Dev

Filtered bool vs Bool query : elasticsearch

From Dev

Elasticsearch bool query with multiple and/or flows

From Dev

Elasticsearch bool query with multiple and/or flows

From Dev

ElasticSearch fulltext search with bool query

From Dev

How to combine bool must and sort for elasticsearch

From Dev

How can I get the score of the underlying matching query in a bool query in ElasticSearch?

From Dev

Combining must_not in ElasticSearch Query

From Dev

Identify which query matched in bool query elasticsearch

From Dev

Elasticsearch query results in 'No query registered for [must]'

From Dev

Elasticsearch bool query speed difference in order

From Dev

ElasticSearch bool query with filter doesnt work on field with "-"

From Dev

Elasticsearch bool filter query return results

From Dev

Elasticsearch not sure if i need to use a bool query

From Dev

build elasticsearch bool query in java dynamically

From Dev

Elasticsearch Java API - Bool Query Operator

From Dev

Multiple bool clauses in elasticsearch filter/query

From Dev

ElasticSearch bool query combined with should and filter

From Dev

must match query not working as expected in Elasticsearch

From Dev

must match query not working as expected in Elasticsearch

From Dev

Elasticsearch - combining query_string and bool query in filter

Related Related

  1. 1

    Min_score for a "must" in a bool query in Elasticsearch

  2. 2

    elasticsearch bool query combine must with OR

  3. 3

    Elasticsearch difference between MUST and SHOULD bool query

  4. 4

    Why not use min_score with Elasticsearch?

  5. 5

    Using bool must match and match _all in one elasticsearch query

  6. 6

    Elasticsearch bool query with filter

  7. 7

    Elasticsearch Bool query

  8. 8

    ElasticSearch bool query request

  9. 9

    elasticsearch must query combine OR?

  10. 10

    Filtered bool vs Bool query : elasticsearch

  11. 11

    Elasticsearch bool query with multiple and/or flows

  12. 12

    Elasticsearch bool query with multiple and/or flows

  13. 13

    ElasticSearch fulltext search with bool query

  14. 14

    How to combine bool must and sort for elasticsearch

  15. 15

    How can I get the score of the underlying matching query in a bool query in ElasticSearch?

  16. 16

    Combining must_not in ElasticSearch Query

  17. 17

    Identify which query matched in bool query elasticsearch

  18. 18

    Elasticsearch query results in 'No query registered for [must]'

  19. 19

    Elasticsearch bool query speed difference in order

  20. 20

    ElasticSearch bool query with filter doesnt work on field with "-"

  21. 21

    Elasticsearch bool filter query return results

  22. 22

    Elasticsearch not sure if i need to use a bool query

  23. 23

    build elasticsearch bool query in java dynamically

  24. 24

    Elasticsearch Java API - Bool Query Operator

  25. 25

    Multiple bool clauses in elasticsearch filter/query

  26. 26

    ElasticSearch bool query combined with should and filter

  27. 27

    must match query not working as expected in Elasticsearch

  28. 28

    must match query not working as expected in Elasticsearch

  29. 29

    Elasticsearch - combining query_string and bool query in filter

HotTag

Archive