Cache a bool query without filter


(Harpreet Bhatia) #1

I have a query like below to search and I want to cache it without using filter.
The code below works well but i could not use "_cache":true with it.

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "keywords": "heart"
          }
        },
        {
          "match": {
            "treatment_name": "heart"
          }
        },
        {
          "wildcard": {
            "keywords": "heart*"
          }
        },
        {
          "wildcard": {
            "treatment_name": "heart*"
          }
        },
        {
          "fuzzy": {
            "keywords": "heart"
          }
        },
        {
          "fuzzy": {
            "treatment_name": "heart"
          }
        }
      ],
      "minimum_should_match": 2
    }
  }
}

The second code works too but the result does not have any score, which is very much required.

{
  "filter": {
    "fquery": {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "keywords": "heart"
              }
            },
            {
              "match": {
                "treatment_name": "heart"
              }
            },
            {
              "wildcard": {
                "keywords": "heart*"
              }
            },
            {
              "wildcard": {
                "treatment_name": "heart*"
              }
            },
            {
              "fuzzy": {
                "keywords": "heart"
              }
            },
            {
              "fuzzy": {
                "treatment_name": "heart"
              }
            }
          ],
          "minimum_should_match": 2
        }
      },
      "_cache": true
    }
  }
}

Please help.


(system) #2