# Scripted Fields with multiple fields

**URL:** <https://discuss.elastic.co/t/scripted-fields-with-multiple-fields/203570>\
**Category:** Kibana\
**Created:** [October 15, 2019, 6:55am UTC](https://discuss.elastic.co/t/scripted-fields-with-multiple-fields/203570 "2019-10-15T06:55:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vladpov](https://avatars.discourse-cdn.com/v4/letter/v/8c91f0/32.png) [@Vladpov](https://discuss.elastic.co/u/Vladpov)\
**Post date:** [October 15, 2019, 6:55am UTC](https://discuss.elastic.co/t/scripted-fields-with-multiple-fields/203570/1 "2019-10-15T06:55:37Z")

</div>

Hi everyone!

I have the following dataframe grouped by field num1:

 ![Sn%C3%ADmek%20obrazovky%20(84)](https://us1.discourse-cdn.com/elastic/original/3X/0/9/0956392d9b82b65eb264fdcd0618af093f5dba4f.png)

I'm trying to create a Scripted Field which can tell me which num1 has both suffices dn and mt.

Is that possible? I mean can I work with two different fields in script?

I'm trying the following script but it gives me only 'bad' state.

```
def m = doc['suffix.keyword'].value;

if (doc['num1.keyword'].value + '-' + m == 'dn' && m == 'mt' ){
return 'Good'
}

return 'Bad';

```

Thanks for any help!

---

<div class="post-metadata">

**Author:** ![azasypkin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/azasypkin/32/42216_2.png) [@azasypkin](https://discuss.elastic.co/u/azasypkin)\
**Post date:** [October 15, 2019, 12:39pm UTC](https://discuss.elastic.co/t/scripted-fields-with-multiple-fields/203570/2 "2019-10-15T12:39:46Z")

</div>

Hi @Vladpov,

> [@Vladpov](#):
>
> I mean can I work with two different fields in script?

Yeah, it should work.

Can you post a sample of your data that I can ingest locally and try it out? I'm not sure I completely understand what you're trying to achieve with this statement `doc['num1.keyword'].value + '-' + m == 'dn' && m == 'mt' `.

Best,  
Oleg

---

<div class="post-metadata">

**Author:** ![Vladpov](https://avatars.discourse-cdn.com/v4/letter/v/8c91f0/32.png) [@Vladpov](https://discuss.elastic.co/u/Vladpov)\
**Post date:** [October 15, 2019, 4:54pm UTC](https://discuss.elastic.co/t/scripted-fields-with-multiple-fields/203570/3 "2019-10-15T16:54:10Z")

</div>

Thank you for reply!

There is a sample of data fist field is timestamp second num1.keyword and third is suffix.keyword

```
Jul 23, 2019 @ 11:24:18.000	1563866656871111	dn
Jul 23, 2019 @ 11:24:18.000	1563866656872222	dn
Jul 23, 2019 @ 11:24:18.000	1563866656876839	dn
Sep 4, 2019 @ 15:24:18.000	1563866656878888	dn
Jul 26, 2019 @ 19:44:18.000	1563867854323333	dn
Jul 26, 2019 @ 19:44:18.000	1563867854324841	dn
Jul 4, 2019 @ 15:56:17.000	1562241377271986	mt
Jul 4, 2019 @ 15:56:17.000	1562241377327366	mt
Jul 4, 2019 @ 15:56:17.000	1562241377361430	mt
Jul 4, 2019 @ 15:56:17.000	1562241377394376	mt
Jul 23, 2019 @ 11:24:16.000	1563866656871111	mt
Jul 23, 2019 @ 11:24:16.000	1563866656876839	mt
Sep 4, 2019 @ 15:24:16.000	1563866656878888	mt
Jul 26, 2019 @ 19:44:14.000	1563867854324841	mt
Jul 26, 2019 @ 19:44:14.000	1563867854325555	mt

```

I thought `doc['num1.keyword'].value + '-' + m == 'dn' && m == 'mt'` that this code could say which num1.keyword has appropriate m (suffix.keyword) value and I need it to have both so dn and mt....

But I found out that it just concatenates the fields 😃

---

<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:** [November 12, 2019, 4:54pm UTC](https://discuss.elastic.co/t/scripted-fields-with-multiple-fields/203570/4 "2019-11-12T16:54:16Z")

</div>

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