# ES 2.14 search query upgrade to ES 8.x

**URL:** <https://discuss.elastic.co/t/es-2-14-search-query-upgrade-to-es-8-x/314701>\
**Category:** Elasticsearch\
**Tags:** kql-kibana-query-language\
**Created:** [September 19, 2022, 2:13pm UTC](https://discuss.elastic.co/t/es-2-14-search-query-upgrade-to-es-8-x/314701 "2022-09-19T14:13:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![VV1002](https://avatars.discourse-cdn.com/v4/letter/v/9dc877/32.png) [@VV1002](https://discuss.elastic.co/u/VV1002)\
**Post date:** [September 19, 2022, 2:13pm UTC](https://discuss.elastic.co/t/es-2-14-search-query-upgrade-to-es-8-x/314701/1 "2022-09-19T14:13:58Z")

</div>

Hi ES Team,

I have a search query which is written in ES 2.14. How do I upgrade that query to version 8.X ? I am confused about how to alter the filter bool query(2.14) because its now filter context and not sure how to move the bool part of the filter to the query part.

Here is the original 2.14 query

```auto
"query":{
    "bool":{
      "{{#search}}must":{
        "bool":{
          "must":{
            "bool":{
              "minimum_should_match":1,
              "should":[
                {
                  "query_string":{
                    "fields":[
                      "act.{{lang}}{{#use_exact}}.exact{{/use_exact}}^6",
                      "act.{{lang}}.folded^6",
                      "title.{{lang}}{{#use_exact}}.exact{{/use_exact}}^10",
                      "title.{{lang}}.folded^10"
                    ],
                    "boost":2,
                    "query":"{{query}}",
                    "analyze_wildcard":true,
                    "auto_generate_synonyms_phrase_query":true,
                    "default_operator":"AND",
                    "lenient":true,
                    "type":"phrase",
                    "tie_breaker":0
                  }
                },
                {
                  "query_string":{
                    "fields":[
                      "text.{{lang}}{{#use_exact}}.exact{{/use_exact}}",
                      "text.{{lang}}.folded^2",
                      "text.{{lang}}.shingles^4"
                    ],
                    "query":"{{query}}",
                    "analyze_wildcard":true,
                    "auto_generate_synonyms_phrase_query":true,
                    "default_operator":"AND",
                    "lenient":true,
                    "minimum_should_match":1,
                    "type":"phrase"
                  }
                }
              ]
            }
          },
          "should":[
            "{{#phrases}}",
            {
              "match":{
                "text.{{lang}}.shingles":{
                  "query":"{{.}}",
                  "boost":4
                }
              }
            },
            "{{/phrases}}",
            {
              "match":{
                "text.{{lang}}.shingles":{
                  "query":"{{terms}}",
                  "boost":2
                }
              }
            }
          ],
          "minimum_should_match":0
        }
      },
      "{{/search}}filter":{
        "bool":{
          "must":[
            "{{#result_search}}",
            {
              "query":{
                "multi_match":{
                  "fields":[
                    "act.{{lang}}.folded^2",
                    "title.{{lang}}.folded^2",
                    "text.{{lang}}",
                    "text.{{lang}}.folded"
                  ],
                  "query":"{{terms}}",
                  "zero_terms_query":"all"
                }
              }
            },
            "{{/result_search}}{{#sort_letter}}",
            {
              "prefix":{
                "act.{{lang}}.prefix":"{{sort_letter}}"
              }
            },
            "{{/sort_letter}}{{#source_pattern}}",
            {
              "regexp":{
                "code":"{{source_pattern}}"
              }
            },
            "{{/source_pattern}}{{#year}}",
            {
              "term":{
                "year":"{{year}}"
              }
            },
            "{{/year}}{{#pit_date}}",
            {
              "bool":{
                "should":[
                  {
                    "bool":{
                      "must":[
                        {
                          "term":{
                            "state.{{lang}}":"historical"
                          }
                        },
                        {
                          "range":{
                            "dateFrom.{{lang}}":{
                              "lte":"{{pit_date}}"
                            }
                          }
                        },
                        {
                          "range":{
                            "dateTo.{{lang}}":{
                              "gte":"{{pit_date}}"
                            }
                          }
                        }
                      ]
                    }
                  },
                  {
                    "bool":{
                      "must":[
                        {
                          "term":{
                            "state.{{lang}}":"current"
                          }
                        },
                        {
                          "range":{
                            "dateFrom.{{lang}}":{
                              "lte":"{{pit_date}}"
                            }
                          }
                        }
                      ]
                    }
                  }
                ]
              }
            },
            "{{/pit_date}}",
            {
              "terms":{
                "state.{{lang}}":[
                  "{{#show_current}}",
                  "current",
                  "{{/show_current}}{{#show_rrs}}",
                  "rrs",
                  "{{/show_rrs}}",
                  "{{#state}}{{.}}{{/state}}"
                ],
                "execution":"bool"
              }
            }
          ]
        }
      }
    }
  }

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 17, 2022, 2:14pm UTC](https://discuss.elastic.co/t/es-2-14-search-query-upgrade-to-es-8-x/314701/2 "2022-10-17T14:14:07Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
