# In scripted fields avoid No field found for \[\] in mapping with types

**URL:** <https://discuss.elastic.co/t/in-scripted-fields-avoid-no-field-found-for-in-mapping-with-types/82883>\
**Category:** Kibana\
**Created:** [April 19, 2017, 12:13pm UTC](https://discuss.elastic.co/t/in-scripted-fields-avoid-no-field-found-for-in-mapping-with-types/82883 "2017-04-19T12:13:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreAga](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@AndreAga](https://discuss.elastic.co/u/AndreAga)\
**Post date:** [April 19, 2017, 12:13pm UTC](https://discuss.elastic.co/t/in-scripted-fields-avoid-no-field-found-for-in-mapping-with-types/82883/1 "2017-04-19T12:13:21Z")

</div>

Hi,  
I'm trying to join/filter two fields stored in two different indeces in the same dashboard.

This is my scenario:

- INDEXA has the field X and Z;
- INDEXB has the field Y and Z.

X and Y contain some values in common.

In the same dashboard I have 4 tables:

1. Shows the values of Z in INDEXA;
2. Shows the values of Z in INDEXB;
3. Shows the values of X in INDEXA;
4. Shows the values of Y in INDEXB;

Now, if I filter for X, only the table 1 updates and vice versa for Y. If I filter for Z, all tables updates.

So, I created a scripted field for INDEXA, called J, that return the value of X and I did the same for INDEXB.

Now I have the following tables:

1. Shows the values of Z in INDEXA;
2. Shows the values of Z in INDEXB;
3. Shows the values of J (X) in INDEXA;
4. Shows the values of J (Y) in INDEXB;

Now, if I filter for J (X), I receive this error:

> java.lang.IllegalArgumentException: No field found for [X.keyword] in mapping with types

and vice versa with J (Y):

> java.lang.IllegalArgumentException: No field found for [Y.keyword] in mapping with types

This is one of the J scripted fields:

> def x = doc['x.keyword'].value;  
> if (x != null) {  
> return x;  
> } else {  
> return "";  
> }

Is there a way to avoid this kind of error? Or, better, make this kind of "join"?

Thanks.

---

<div class="post-metadata">

**Author:** ![cjcenizal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjcenizal/32/11216_2.png) [@cjcenizal](https://discuss.elastic.co/u/cjcenizal)\
**Post date:** [April 19, 2017, 8:51pm UTC](https://discuss.elastic.co/t/in-scripted-fields-avoid-no-field-found-for-in-mapping-with-types/82883/2 "2017-04-19T20:51:08Z")

</div>

Can you do a check if the doc property exists before getting a value on it?

```auto
def x = doc['x.keyword'];
if (x != null) {
return x.value;
} else {
return "";
}

```

---

<div class="post-metadata">

**Author:** ![cjcenizal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjcenizal/32/11216_2.png) [@cjcenizal](https://discuss.elastic.co/u/cjcenizal)\
**Post date:** [April 19, 2017, 8:56pm UTC](https://discuss.elastic.co/t/in-scripted-fields-avoid-no-field-found-for-in-mapping-with-types/82883/3 "2017-04-19T20:56:15Z")

</div>

Sorry, that also results in the same error. This should work instead:

```auto
if (doc.containsKey('x.keyword')) {
  return doc['x.keyword'].value;
} else {
  return '';
}

```

---

<div class="post-metadata">

**Author:** ![AndreAga](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@AndreAga](https://discuss.elastic.co/u/AndreAga)\
**Post date:** [April 20, 2017, 8:44am UTC](https://discuss.elastic.co/t/in-scripted-fields-avoid-no-field-found-for-in-mapping-with-types/82883/4 "2017-04-20T08:44:46Z")

</div>

Thank you, the error has gone, but the filter doesn't work.  
If I select a value in J (X) that appears also in J (Y), the result is that the J (Y) table is empty. Any way to do that?

EDIT:  
I create a new scripted field with both X.keyword and Y.keyword.. I think the same scripted field is executed in all indeces, when I select a value in it, correct?

> if (doc.containsKey('X.keyword')) {  
> def val = doc['x.keyword'].value;  
> if (val != null) {  
> return val;  
> } else {  
> return "";  
> }  
> } else if (doc.containsKey('Y.keyword')) {  
> def val = doc['Y.keyword'].value;  
> if (val != null) {  
> return val;  
> } else {  
> return "";  
> }  
> } else {  
> return "";  
> }

With this script, replicated in both INDEXA and INDEXB, I'm able to filter the same values, stored in different fields and in different indeces.

---

<div class="post-metadata">

**Author:** ![cjcenizal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjcenizal/32/11216_2.png) [@cjcenizal](https://discuss.elastic.co/u/cjcenizal)\
**Post date:** [April 20, 2017, 8:27pm UTC](https://discuss.elastic.co/t/in-scripted-fields-avoid-no-field-found-for-in-mapping-with-types/82883/5 "2017-04-20T20:27:45Z")

</div>

Yes, your scripted field will be applied to all indices captured by your index pattern. Is everything working OK for you now?

Thanks,  
CJ

---

<div class="post-metadata">

**Author:** ![AndreAga](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@AndreAga](https://discuss.elastic.co/u/AndreAga)\
**Post date:** [April 21, 2017, 7:22am UTC](https://discuss.elastic.co/t/in-scripted-fields-avoid-no-field-found-for-in-mapping-with-types/82883/6 "2017-04-21T07:22:13Z")

</div>

Yep, thank you. 🙂

---

<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 19, 2017, 7:36am UTC](https://discuss.elastic.co/t/in-scripted-fields-avoid-no-field-found-for-in-mapping-with-types/82883/7 "2017-05-19T07:36:17Z")

</div>

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