Elasticsearch multiple fields OR query

Shail Patel

Here is an example record that I have stored in ES:

  "taskCurateStatus": true,
  "taskMigrateStatus": true,
  "verifiedFields": 7,
  "taskId": "abcdef123",
  "operatorEmail": "[email protected]"

Example Query I'm making via /_search:
{
  "sort": [
    {
      "@timestamp": {
        "order": "desc"
      }
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "msg.operator_email": "[email protected]"
          }
        }
        {
          "range": {
            "@timestamp": {
              "gte": "2017-03-05",
              "lte": "2017-03-12"
            }
          }
        }
      ]
    }
  },
  "from": 0,
  "size": 50
}

Basically I want to also filter by documents that have EITHER taskCurateStatus or taskMigrateStatus be true. Some messages have only one of them defined. I was thinking of using a should query but not sure how that would work with the match query. Any help would be appreciated. Thanks

user3775217

you can add another boolean filter inside your must filter. This boolean filter can implemenet the should clause where you can compare the boolean flags with a should filter combining both the boolean check filters

{
    "sort": [{
        "@timestamp": {
            "order": "desc"
        }
    }],
    "query": {
        "bool": {
            "must": [{
                "match": {
                    "msg.operator_email": "[email protected]"
                }
            }, {
                "range": {
                    "@timestamp": {
                        "gte": "2017-03-05",
                        "lte": "2017-03-12"
                    }
                }
            }, {
                "bool": {
                    "should": [{
                        "term": {
                            "taskCurateStatus": {
                                "value": true
                            }
                        }
                    }, {
                        "term": {
                            "taskMigrateStatus": {
                                "value": true
                            }
                        }
                    }]
                }
            }]
        }
    },
    "from": 0,
    "size": 50
}

Take a look at the above query and see if the helps Thanks

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Elasticsearch phrase prefix query on multiple fields

From Dev

Elasticsearch: query for multiple words across multiple fields (with prefix)

From Dev

How to add multiple fields to a common terms query in ElasticSearch?

From Dev

Elasticsearch find exact text in multiple fields using single query

From Dev

ElasticSearch multi_match query over multiple fields with Fuzziness

From Dev

Match phrase query with multiple fields in elasticsearch using nest

From Dev

ElasticSearch group by multiple fields

From Dev

Elasticsearch match multiple fields

From Dev

Search on multiple fields with Elasticsearch

From Dev

Elasticsearch multiple fields autosuggestion

From Dev

Elasticsearch match multiple fields

From Dev

Query nested fields with elasticsearch in grails

From Dev

elasticsearch: rename output fields of query

From Dev

Different relevance of fields in elasticsearch query

From Dev

AngularFire query on multiple fields

From Dev

ElasticSearch sort order for multiple fields

From Dev

Search on multiple fields with ElasticSearch with or, and operators

From Dev

ElasticSearch and searching on multiple fields in PHP

From Dev

ElasticSearch filtering on multiple fields (with aggregration)

From Dev

ElasticSearch and searching on multiple fields in PHP

From Dev

Elasticsearch sort based on multiple fields

From Dev

Elasticsearch: multiple languages in two fields when the query's language is unknown or mixed

From Dev

Does an elasticsearch simple_query_string query use dis_max or bool to combine queries when multiple fields are specified?

From Dev

Endeca search query on multiple fields

From Dev

Couchbase : view or query on multiple fields (OR)

From Dev

Replace multiple fields with one query

From Dev

MongoDB query for multiple fields in a collection

From Dev

query collection for multiple fields with Linq

From Dev

Couchbase : view or query on multiple fields (OR)

Related Related

  1. 1

    Elasticsearch phrase prefix query on multiple fields

  2. 2

    Elasticsearch: query for multiple words across multiple fields (with prefix)

  3. 3

    How to add multiple fields to a common terms query in ElasticSearch?

  4. 4

    Elasticsearch find exact text in multiple fields using single query

  5. 5

    ElasticSearch multi_match query over multiple fields with Fuzziness

  6. 6

    Match phrase query with multiple fields in elasticsearch using nest

  7. 7

    ElasticSearch group by multiple fields

  8. 8

    Elasticsearch match multiple fields

  9. 9

    Search on multiple fields with Elasticsearch

  10. 10

    Elasticsearch multiple fields autosuggestion

  11. 11

    Elasticsearch match multiple fields

  12. 12

    Query nested fields with elasticsearch in grails

  13. 13

    elasticsearch: rename output fields of query

  14. 14

    Different relevance of fields in elasticsearch query

  15. 15

    AngularFire query on multiple fields

  16. 16

    ElasticSearch sort order for multiple fields

  17. 17

    Search on multiple fields with ElasticSearch with or, and operators

  18. 18

    ElasticSearch and searching on multiple fields in PHP

  19. 19

    ElasticSearch filtering on multiple fields (with aggregration)

  20. 20

    ElasticSearch and searching on multiple fields in PHP

  21. 21

    Elasticsearch sort based on multiple fields

  22. 22

    Elasticsearch: multiple languages in two fields when the query's language is unknown or mixed

  23. 23

    Does an elasticsearch simple_query_string query use dis_max or bool to combine queries when multiple fields are specified?

  24. 24

    Endeca search query on multiple fields

  25. 25

    Couchbase : view or query on multiple fields (OR)

  26. 26

    Replace multiple fields with one query

  27. 27

    MongoDB query for multiple fields in a collection

  28. 28

    query collection for multiple fields with Linq

  29. 29

    Couchbase : view or query on multiple fields (OR)

HotTag

Archive