i am just using ES to filter out some data, not need score function at all. but there are some or logic i have to include. i know we can replace must with filter, so ES will not score it and may cache it. How to profile should cause?

it this two query have different?

{
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "should": [
              {
                "term": {
                  "closeStatus": 0
                }
              },
              {
                "bool": {
                  "must_not": {
                    "exists": {
                      "field": "closeStatus"
------------------------------------------------
{
  "query": {
    "bool": {
      "should": [
        {
          "term": {
            "closeStatus": 0
          }
        },
        {
          "bool": {
            "must_not": {
              "exists": {
                "field": "closeStatus"

1 Answers

1
Tomáš Linhart On Best Solutions

If you don't care about the score, use constant_score query:

{
  "query": {
    "constant_score": {
      "filter": {
        "bool": {
          "should": [
            {
              "term": {
                "closeStatus": 0
              }
            },
            {
              "bool": {
                "must_not": {
                  "exists": {"field": "closeStatus"}
                }
              }
            }
          ]
        }
      }
    }
  }
}