# ESE : Practice Exam - Task 5 Solution - Alternative

**URL:** <https://discuss.elastic.co/t/ese-practice-exam-task-5-solution-alternative/271583>\
**Category:** Elastic Training\
**Created:** [April 29, 2021, 4:58am UTC](https://discuss.elastic.co/t/ese-practice-exam-task-5-solution-alternative/271583 "2021-04-29T04:58:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![suselena22](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@suselena22](https://discuss.elastic.co/u/suselena22)\
**Post date:** [April 29, 2021, 4:58am UTC](https://discuss.elastic.co/t/ese-practice-exam-task-5-solution-alternative/271583/1 "2021-04-29T04:58:03Z")

</div>

Hi There:  
The solution was given in the Practice Exam, just a bit confused with the custom analyzer and script query. Please advise, appreciate your helps. Thank you so much, see below Task 5 question and solutions

Task 5 Question  
Create a new index on `cluster1` named `task5` that satisfies the following requirements:

- contains all of the documents from the `blogs` index
- whenever the string **UK** (both capital letters) appears in the `content` field, it gets replaced with **United Kingdom**

Practice Exam Given solution

```auto
PUT task5
{
  "settings": {
    "analysis": {
      "char_filter": {
        "uk_filter": {
          "type": "mapping",
          "mappings": [
            "UK => United Kingdom"
            ]
        }
      },
      "analyzer": {
        "content_analyzer": {
          "tokenizer": "standard",
          "char_filter": ["uk_filter"]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "content": {
        "type": "text",
        "analyzer": "content_analyzer"
      }
    }
  }
}

POST _reindex
{
  "source": {
    "index": "blogs"
  },
  "dest": {
    "index": "task5"
  }
}

```

Why not this solution? (my own) 🙂

```auto
POST _reindex
{
  "source": {
    "index": "blogs"
  },
  "dest": {
    "index": "task5"
  },
  "script": {
    "source": "if (ctx['content'] == 'UK') {ctx['content']=='United Kingdom'}",
    "lang": "painless"
  }
}

```

---

<div class="post-metadata">

**Author:** ![Peter\_Steenbergen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_steenbergen/32/22888_2.png) [@Peter\_Steenbergen](https://discuss.elastic.co/u/Peter_Steenbergen)\
**Post date:** [April 29, 2021, 6:46am UTC](https://discuss.elastic.co/t/ese-practice-exam-task-5-solution-alternative/271583/2 "2021-04-29T06:46:56Z")

</div>

Your solution would work, but it would be a one time operation.  
When doing the \_reindex only with a script, you would have to rerun your script, or do an update by query to make new data coming in to be analyzed also for UK =\> United Kingdom.

With setting it in the mapping new data ingested gets analyzed automatically with the new index in play. So it 'fixes' the current data of the old index while keeping it correct with new incoming data.

---

<div class="post-metadata">

**Author:** ![dschneiter](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dschneiter/32/46162_2.png) [@dschneiter](https://discuss.elastic.co/u/dschneiter)\
**Post date:** [April 29, 2021, 6:56am UTC](https://discuss.elastic.co/t/ese-practice-exam-task-5-solution-alternative/271583/3 "2021-04-29T06:56:36Z")

</div>

Hi @suselena22

I’d like to add another aspect to Peter’s response: Often there is not just one way of getting a task solved. Having said so, if your solution is different, but solves the task set, it should be fine.

Just carefully read the task in the exam, whether you are asked to apply a “one-time” fix or a “general” fix.

Daniel

---

<div class="post-metadata">

**Author:** ![suselena22](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@suselena22](https://discuss.elastic.co/u/suselena22)\
**Post date:** [April 29, 2021, 10:18am UTC](https://discuss.elastic.co/t/ese-practice-exam-task-5-solution-alternative/271583/4 "2021-04-29T10:18:50Z")

</div>

This is awesome, I'm now fully understand the advantage of having the custom analyzer and script query. So, the custom analyzer is definitely a better solution because it fixes the current data and future data.

Thank you Peter 🤩 🤩

---

<div class="post-metadata">

**Author:** ![suselena22](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@suselena22](https://discuss.elastic.co/u/suselena22)\
**Post date:** [April 29, 2021, 10:20am UTC](https://discuss.elastic.co/t/ese-practice-exam-task-5-solution-alternative/271583/5 "2021-04-29T10:20:11Z")

</div>

Thank you for the message and tips, Daniel. I'm now have more confident to sit for the exam 🤩 🤩

---

<div class="post-metadata">

**Author:** ![pmusa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pmusa/32/3498_2.png) [@pmusa](https://discuss.elastic.co/u/pmusa)\
**Post date:** [April 30, 2021, 9:17am UTC](https://discuss.elastic.co/t/ese-practice-exam-task-5-solution-alternative/271583/6 "2021-04-30T09:17:36Z")

</div>

You could easily add your script to an ingest pipeline and also fix new/future data.

That said, I don't think that this is the best solution as it changes the data itself and many times that is not what users want. The main advantage of the analysis option is that it only changes the internal data structures used to search.

---

<div class="post-metadata">

**Author:** ![suselena22](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@suselena22](https://discuss.elastic.co/u/suselena22)\
**Post date:** [April 30, 2021, 9:30am UTC](https://discuss.elastic.co/t/ese-practice-exam-task-5-solution-alternative/271583/7 "2021-04-30T09:30:27Z")

</div>

Nice, thanks Pablo

---

<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:** [May 30, 2021, 9:30am UTC](https://discuss.elastic.co/t/ese-practice-exam-task-5-solution-alternative/271583/8 "2021-05-30T09:30:39Z")

</div>

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