# Can I use 'indexOf(keyword)' like Java when I query by Custom Score?

**URL:** <https://discuss.elastic.co/t/can-i-use-indexof-keyword-like-java-when-i-query-by-custom-score/14511>\
**Category:** Elasticsearch\
**Created:** [November 21, 2013, 8:11am UTC](https://discuss.elastic.co/t/can-i-use-indexof-keyword-like-java-when-i-query-by-custom-score/14511 "2013-11-21T08:11:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Min\_Cha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/min_cha/32/1131_2.png) [@Min\_Cha](https://discuss.elastic.co/u/Min_Cha)\
**Post date:** [November 21, 2013, 8:11am UTC](https://discuss.elastic.co/t/can-i-use-indexof-keyword-like-java-when-i-query-by-custom-score/14511/1 "2013-11-21T08:11:53Z")

</div>

Hello all.

I have a question.  
For example, there are documents as following.

1. Love is blue.
2. Blue is love.
3. Red is not love.

In this case if I apply indexOf('Love'), result is as following.

1. Love is blue = index 0
2. Love is blue = index 8
3. Love is blue = index 12

Finally, I would like to compute score like following pseudo syntax.

script : "\_score \* sentence.indexOf(keyword)"

In ElasticSearch, is this possible?  
Please give me some advice.

Thanks for reading.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Min\_Cha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/min_cha/32/1131_2.png) [@Min\_Cha](https://discuss.elastic.co/u/Min_Cha)\
**Post date:** [November 22, 2013, 3:09am UTC](https://discuss.elastic.co/t/can-i-use-indexof-keyword-like-java-when-i-query-by-custom-score/14511/2 "2013-11-22T03:09:15Z")

</div>

Hello.

I have resolved this issue.  
Following is a example to resolve my problem.

{"query":{"custom\_score":{"query":{"query\_string":{"query":"title:"Love""}},"script":"\_source.weight

- new String(\_source.title).indexOf("Love") \* 0.00001"}}}

2013년 11월 21일 목요일 오후 5시 11분 53초 UTC+9, Min Cha 님의 말:

> Hello all.
> 
> I have a question.  
> For example, there are documents as following.
> 
> 1. Love is blue.
> 2. Blue is love.
> 3. Red is not love.
> 
> In this case if I apply indexOf('Love'), result is as following.
> 
> 1. Love is blue = index 0
> 2. Love is blue = index 8
> 3. Love is blue = index 12
> 
> Finally, I would like to compute score like following pseudo syntax.
> 
> script : "\_score \* sentence.indexOf(keyword)"
> 
> In Elasticsearch, is this possible?  
> Please give me some advice.
> 
> Thanks for reading.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:05am UTC](https://discuss.elastic.co/t/can-i-use-indexof-keyword-like-java-when-i-query-by-custom-score/14511/3 "2017-07-06T02:05:32Z")

</div>


