# Elasticsearch Engineer - Lab 2.4 - Error in instructions

**URL:** <https://discuss.elastic.co/t/elasticsearch-engineer-lab-2-4-error-in-instructions/295278>\
**Category:** Elastic Training\
**Created:** [January 24, 2022, 8:00pm UTC](https://discuss.elastic.co/t/elasticsearch-engineer-lab-2-4-error-in-instructions/295278 "2022-01-24T20:00:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Irina\_Truong](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irina_truong/32/112040_2.png) [@Irina\_Truong](https://discuss.elastic.co/u/Irina_Truong)\
**Post date:** [January 24, 2022, 8:00pm UTC](https://discuss.elastic.co/t/elasticsearch-engineer-lab-2-4-error-in-instructions/295278/1 "2022-01-24T20:00:53Z")

</div>

Dear Elasticsearch training experts,

I've been going through the Elasticsearch Engineer class. In the lab 2.4 "Advanced search" there is a task as follows:

> Write a script query that returns all blogs where the authors.last\_name.keyword field starts with the letter "K". There are multiple ways to write this code, but you can use the startsWith() function. You should get 371 hits. HINT: you will get an error is you do not check for empty values of authors.last\_name.keyword. You could either check that the size() function of doc['authors.last\_name.keyword'] is greater than 0, or incorporate the exists query in your bool qeury.

The suggested answer is a script like this:

```auto
if(doc['authors.last_name.keyword'].size() > 0 && doc['authors.last_name.keyword'].value.startsWith("K"))
  return true;

```

The script returns 371 results. However, this answer is not complete. **Each blog may have multiple authors.** The suggested script picks the first author and checks if the name of this author starts with a K. This is not covering a case of having 2, 3 or more authors, and the one whose name starts with a K not being first in the list.

A script similar to the following would produce a more full answer. It would return 433 results:

```auto
def authors = doc["authors.last_name.keyword"];
for (int i = 0; i < authors.size(); i++) {
  if (authors.get(i).startsWith("K")) {
    return true;
  }
}
return false;

```

Also, there's a couple of typos in the task text (" **will get an error is you**" and " **qeury**").

I was looking for somewhere to submit feedback / create an issue in the class environment, but I could not find anything. I emailed [training@elastic.co](mailto:training@elastic.co) and was advised to post in the forum here.

Thank you.

---

<div class="post-metadata">

**Author:** ![Mark\_Laney](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_laney/32/44349_2.png) [@Mark\_Laney](https://discuss.elastic.co/u/Mark_Laney)\
**Post date:** [January 24, 2022, 8:40pm UTC](https://discuss.elastic.co/t/elasticsearch-engineer-lab-2-4-error-in-instructions/295278/2 "2022-01-24T20:40:40Z")

</div>

I tested and this looks spot on to me, Irina. Thank you. I'll post this into our Education Issues.

---

<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:** [February 23, 2022, 8:41pm UTC](https://discuss.elastic.co/t/elasticsearch-engineer-lab-2-4-error-in-instructions/295278/3 "2022-02-23T20:41:38Z")

</div>

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