# Kibana kibana script field indexof

**URL:** <https://discuss.elastic.co/t/kibana-kibana-script-field-indexof/109000>\
**Category:** Kibana\
**Created:** [November 24, 2017, 9:36am UTC](https://discuss.elastic.co/t/kibana-kibana-script-field-indexof/109000 "2017-11-24T09:36:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hsiuming](https://avatars.discourse-cdn.com/v4/letter/h/d78d45/32.png) [@hsiuming](https://discuss.elastic.co/u/hsiuming)\
**Post date:** [November 24, 2017, 9:36am UTC](https://discuss.elastic.co/t/kibana-kibana-script-field-indexof/109000/1 "2017-11-24T09:36:58Z")

</div>

Hello

If we now have two field: "event\_data.Binary" and "Binary1".

We want set a script field to get a word position from the field.

We set the script field:

language:painless

type:number

script: doc['event\_data.Binary.keyword'].value.indexOf(doc['Binary1.keyword'])

We will get the error:Courier Fetch: 10 of 15 shards failed.

How could we set the script?

The type of these filed are string.

---

<div class="post-metadata">

**Author:** ![ppisljar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppisljar/32/11588_2.png) [@ppisljar](https://discuss.elastic.co/u/ppisljar)\
**Post date:** [November 24, 2017, 9:47am UTC](https://discuss.elastic.co/t/kibana-kibana-script-field-indexof/109000/2 "2017-11-24T09:47:56Z")

</div>

you are missing .value on your second field

`doc['event_data.Binary.keyword'].value.indexOf(doc['Binary1.keyword'].value)`

---

<div class="post-metadata">

**Author:** ![hsiuming](https://avatars.discourse-cdn.com/v4/letter/h/d78d45/32.png) [@hsiuming](https://discuss.elastic.co/u/hsiuming)\
**Post date:** [November 24, 2017, 9:57am UTC](https://discuss.elastic.co/t/kibana-kibana-script-field-indexof/109000/3 "2017-11-24T09:57:30Z")

</div>

hello ppisljar

I set the script and kibana always show "Courier Fetch: 10 of 15 shards failed."

Kibana also have no data showing.

Is there any other issue?

And I have another question.

Could we set the script condition only for Specified event?

For example,if the event message is "hello" only can use this script.

I don't want all field to use this script.

Thanks

here is the picture:

 ![未命名](https://us1.discourse-cdn.com/elastic/original/3X/c/b/cb00647d973a37130ca00b117748f30130479a49.png)

 ![未命名](https://us1.discourse-cdn.com/elastic/original/3X/3/4/347245757c6af82410790761bbe0aa6d27307ba1.png)

---

<div class="post-metadata">

**Author:** ![ppisljar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppisljar/32/11588_2.png) [@ppisljar](https://discuss.elastic.co/u/ppisljar)\
**Post date:** [November 24, 2017, 10:30am UTC](https://discuss.elastic.co/t/kibana-kibana-script-field-indexof/109000/4 "2017-11-24T10:30:07Z")

</div>

there are plenty of things that could go wrong ...

first, its good to check if the fields exist with `doc.containsKey('fieldName')`

```auto
if (doc.containsKey('event_data.Binary.keyword') && doc.containsKey('Binary1.keyword')) {
 return doc['event_data.Binary.keyword'].value.indexOf(doc['Binary1.keyword'].value);
} else {
 return 0;
}

```

maybe its better if we talk about how to debug your scripts ....

- create a visualization, that will throw the error
- open spy panel, go to the `request` tab
- copy request to clipboard
- go to `Dev Tools` app (in the menu on the left where Visualize and Dashbord are)
- write in `GET _search` in the first line and below it paste your JSON request you copied
- click on play icon ... in the response on the right you should get more info about what went wrong

however if shards are failing you might not get anything back ...  
then you should look at your elasticsearch log and see why the shards failed.

---

<div class="post-metadata">

**Author:** ![hsiuming](https://avatars.discourse-cdn.com/v4/letter/h/d78d45/32.png) [@hsiuming](https://discuss.elastic.co/u/hsiuming)\
**Post date:** [November 27, 2017, 10:31am UTC](https://discuss.elastic.co/t/kibana-kibana-script-field-indexof/109000/5 "2017-11-27T10:31:55Z")

</div>

Hello ppisljar

Now I change the out form to avoid this issue.

The output is "AAAAA\_BB".

How can I set the script field to get two fields that the content of these two field are AAAAA and BB ?

---

<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:** [December 25, 2017, 10:32am UTC](https://discuss.elastic.co/t/kibana-kibana-script-field-indexof/109000/6 "2017-12-25T10:32:16Z")

</div>

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