# Using Script field in Search Query

**URL:** <https://discuss.elastic.co/t/using-script-field-in-search-query/7520>\
**Category:** Elasticsearch\
**Created:** [May 1, 2012, 7:16am UTC](https://discuss.elastic.co/t/using-script-field-in-search-query/7520 "2012-05-01T07:16:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rahul\_Sharma](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@Rahul\_Sharma](https://discuss.elastic.co/u/Rahul_Sharma)\
**Post date:** [May 1, 2012, 7:16am UTC](https://discuss.elastic.co/t/using-script-field-in-search-query/7520/1 "2012-05-01T07:16:29Z")

</div>

Hi,

Stuck with a simple issue, it would be really great if any of you can help  
me out.

Trying to use a scriptField in a search query. But as I execute the query,  
it runs forever does not come out of execution. Am I doing something wrong.  
Here is the code:

SearchRequestBuilder builder = client.prepareSearch(indexName);  
SearchResponse searchResponse =  
builder.setQuery(matchAllQuery()).addScriptField("Amount1",  
"doc['amount'].value").execute().actionGet();

Does not throw any exception, at the same time does not come out of  
execution. Just hangs.

I am using elasticsearch-0.18.5

Thanks  
Rahul

---

<div class="post-metadata">

**Author:** ![jagdeep](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jagdeep](https://discuss.elastic.co/u/jagdeep)\
**Post date:** [May 1, 2012, 7:32am UTC](https://discuss.elastic.co/t/using-script-field-in-search-query/7520/2 "2012-05-01T07:32:45Z")

</div>

Which Port you bare using? 9300 or 9200?  
Please give more details about mapping and configuration.

On May 1, 12:16 pm, Rahul Sharma [rahul.sharma.co...@gmail.com](mailto:rahul.sharma.co...@gmail.com) wrote:

> Hi,
> 
> Stuck with a simple issue, it would be really great if any of you can help  
> me out.
> 
> Trying to use a scriptField in a search query. But as I execute the query,  
> it runs forever does not come out of execution. Am I doing something wrong.  
> Here is the code:
> 
> SearchRequestBuilder builder = client.prepareSearch(indexName);  
> SearchResponse searchResponse =  
> builder.setQuery(matchAllQuery()).addScriptField("Amount1",  
> "doc['amount'].value").execute().actionGet();
> 
> Does not throw any exception, at the same time does not come out of  
> execution. Just hangs.
> 
> I am using elasticsearch-0.18.5
> 
> Thanks  
> Rahul

---

<div class="post-metadata">

**Author:** ![Rahul\_Sharma](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@Rahul\_Sharma](https://discuss.elastic.co/u/Rahul_Sharma)\
**Post date:** [May 1, 2012, 7:43am UTC](https://discuss.elastic.co/t/using-script-field-in-search-query/7520/3 "2012-05-01T07:43:51Z")

</div>

Am using default configuration which uses 9300.  
I am storing "amount" as a field which is a double field.

If I don't use scriptField and just use the below query then I get back all  
the documents as expected.  
builder.setQuery(matchAllQuery()).execute().actionGet();

But when I add scriptField its goes real searching. I tried with String  
field (which is not analyzed) as well. Same result.

Thanks  
Rahul

On Tue, May 1, 2012 at 1:02 PM, jagdeep singh [reach.jagdeep@gmail.com](mailto:reach.jagdeep@gmail.com)wrote:

> Which Port you bare using? 9300 or 9200?  
> Please give more details about mapping and configuration.
> 
> On May 1, 12:16 pm, Rahul Sharma [rahul.sharma.co...@gmail.com](mailto:rahul.sharma.co...@gmail.com) wrote:
> 
> > Hi,
> > 
> > Stuck with a simple issue, it would be really great if any of you can  
> > help  
> > me out.
> > 
> > Trying to use a scriptField in a search query. But as I execute the  
> > query,  
> > it runs forever does not come out of execution. Am I doing something  
> > wrong.  
> > Here is the code:
> > 
> > SearchRequestBuilder builder = client.prepareSearch(indexName);  
> > SearchResponse searchResponse =  
> > builder.setQuery(matchAllQuery()).addScriptField("Amount1",  
> > "doc['amount'].value").execute().actionGet();
> > 
> > Does not throw any exception, at the same time does not come out of  
> > execution. Just hangs.
> > 
> > I am using elasticsearch-0.18.5
> > 
> > Thanks  
> > Rahul

---

<div class="post-metadata">

**Author:** ![Rahul\_Sharma](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@Rahul\_Sharma](https://discuss.elastic.co/u/Rahul_Sharma)\
**Post date:** [May 1, 2012, 6:10pm UTC](https://discuss.elastic.co/t/using-script-field-in-search-query/7520/4 "2012-05-01T18:10:34Z")

</div>

Doing some further research, I could see that the search response is fine  
till

NettyTransportChannel.java --- sendResponse(Streamable message,  
TransportResponseOptions options)  
I assume it should return back the control after  
_channel.write(buffer)_, but it does not seem like happening.

Whereas if I do regular search without addScrieptField everything works fine  
_.  
Note_: Though Scripts are working fine when its used with Facets.

Would appreciate your suggestion / pointers.

Am I doing something wrong or its a potential bug?

Thanks  
Rahul

On Tue, May 1, 2012 at 1:13 PM, Rahul Sharma  
[rahul.sharma.coder@gmail.com](mailto:rahul.sharma.coder@gmail.com)wrote:

> Am using default configuration which uses 9300.  
> I am storing "amount" as a field which is a double field.
> 
> If I don't use scriptField and just use the below query then I get back  
> all the documents as expected.  
> builder.setQuery(matchAllQuery()).execute().actionGet();
> 
> But when I add scriptField its goes real searching. I tried with String  
> field (which is not analyzed) as well. Same result.
> 
> Thanks  
> Rahul
> 
> On Tue, May 1, 2012 at 1:02 PM, jagdeep singh [reach.jagdeep@gmail.com](mailto:reach.jagdeep@gmail.com)wrote:
> 
> > Which Port you bare using? 9300 or 9200?  
> > Please give more details about mapping and configuration.
> > 
> > On May 1, 12:16 pm, Rahul Sharma [rahul.sharma.co...@gmail.com](mailto:rahul.sharma.co...@gmail.com) wrote:
> > 
> > > Hi,
> > > 
> > > Stuck with a simple issue, it would be really great if any of you can  
> > > help  
> > > me out.
> > > 
> > > Trying to use a scriptField in a search query. But as I execute the  
> > > query,  
> > > it runs forever does not come out of execution. Am I doing something  
> > > wrong.  
> > > Here is the code:
> > > 
> > > SearchRequestBuilder builder = client.prepareSearch(indexName);  
> > > SearchResponse searchResponse =  
> > > builder.setQuery(matchAllQuery()).addScriptField("Amount1",  
> > > "doc['amount'].value").execute().actionGet();
> > > 
> > > Does not throw any exception, at the same time does not come out of  
> > > execution. Just hangs.
> > > 
> > > I am using elasticsearch-0.18.5
> > > 
> > > Thanks  
> > > Rahul

---

<div class="post-metadata">

**Author:** ![Rahul\_Sharma](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@Rahul\_Sharma](https://discuss.elastic.co/u/Rahul_Sharma)\
**Post date:** [May 1, 2012, 7:52pm UTC](https://discuss.elastic.co/t/using-script-field-in-search-query/7520/5 "2012-05-01T19:52:43Z")

</div>

I could solve the issue by upgrading to 0.19.3  
But unfortunately I could not find a bug logged around this which got  
solved post 0.18.5

BTW, this can be replicated for addField as well.

On Tue, May 1, 2012 at 11:40 PM, Rahul Sharma  
[rahul.sharma.coder@gmail.com](mailto:rahul.sharma.coder@gmail.com)wrote:

> Doing some further research, I could see that the search response is fine  
> till
> 
> NettyTransportChannel.java --- sendResponse(Streamable message,  
> TransportResponseOptions options)  
> I assume it should return back the control after  
> _channel.write(buffer)_, but it does not seem like happening.
> 
> Whereas if I do regular search without addScrieptField everything works  
> fine\*.  
> Note\*: Though Scripts are working fine when its used with Facets.
> 
> Would appreciate your suggestion / pointers.
> 
> Am I doing something wrong or its a potential bug?
> 
> Thanks  
> Rahul
> 
> On Tue, May 1, 2012 at 1:13 PM, Rahul Sharma \<[rahul.sharma.coder@gmail.com](mailto:rahul.sharma.coder@gmail.com)
> 
> > wrote:
> 
> > Am using default configuration which uses 9300.  
> > I am storing "amount" as a field which is a double field.
> > 
> > If I don't use scriptField and just use the below query then I get back  
> > all the documents as expected.  
> > builder.setQuery(matchAllQuery()).execute().actionGet();
> > 
> > But when I add scriptField its goes real searching. I tried with String  
> > field (which is not analyzed) as well. Same result.
> > 
> > Thanks  
> > Rahul
> > 
> > On Tue, May 1, 2012 at 1:02 PM, jagdeep singh [reach.jagdeep@gmail.com](mailto:reach.jagdeep@gmail.com)wrote:
> > 
> > > Which Port you bare using? 9300 or 9200?  
> > > Please give more details about mapping and configuration.
> > > 
> > > On May 1, 12:16 pm, Rahul Sharma [rahul.sharma.co...@gmail.com](mailto:rahul.sharma.co...@gmail.com) wrote:
> > > 
> > > > Hi,
> > > > 
> > > > Stuck with a simple issue, it would be really great if any of you can  
> > > > help  
> > > > me out.
> > > > 
> > > > Trying to use a scriptField in a search query. But as I execute the  
> > > > query,  
> > > > it runs forever does not come out of execution. Am I doing something  
> > > > wrong.  
> > > > Here is the code:
> > > > 
> > > > SearchRequestBuilder builder = client.prepareSearch(indexName);  
> > > > SearchResponse searchResponse =  
> > > > builder.setQuery(matchAllQuery()).addScriptField("Amount1",  
> > > > "doc['amount'].value").execute().actionGet();
> > > > 
> > > > Does not throw any exception, at the same time does not come out of  
> > > > execution. Just hangs.
> > > > 
> > > > I am using elasticsearch-0.18.5
> > > > 
> > > > Thanks  
> > > > Rahul

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 2, 2012, 4:31pm UTC](https://discuss.elastic.co/t/using-script-field-in-search-query/7520/6 "2012-05-02T16:31:05Z")

</div>

Can you first try and see if it happens with a later version? Its strange  
that you get it... . If it does, can you write a simple Java program that  
recreates the problem?

On Tue, May 1, 2012 at 10:52 PM, Rahul Sharma  
[rahul.sharma.coder@gmail.com](mailto:rahul.sharma.coder@gmail.com)wrote:

> I could solve the issue by upgrading to 0.19.3  
> But unfortunately I could not find a bug logged around this which got  
> solved post 0.18.5
> 
> BTW, this can be replicated for addField as well.
> 
> On Tue, May 1, 2012 at 11:40 PM, Rahul Sharma \<  
> [rahul.sharma.coder@gmail.com](mailto:rahul.sharma.coder@gmail.com)\> wrote:
> 
> > Doing some further research, I could see that the search response is fine  
> > till
> > 
> > NettyTransportChannel.java --- sendResponse(Streamable message,  
> > TransportResponseOptions options)  
> > I assume it should return back the control after  
> > _channel.write(buffer)_, but it does not seem like happening.
> > 
> > Whereas if I do regular search without addScrieptField everything works  
> > fine\*.  
> > Note\*: Though Scripts are working fine when its used with Facets.
> > 
> > Would appreciate your suggestion / pointers.
> > 
> > Am I doing something wrong or its a potential bug?
> > 
> > Thanks  
> > Rahul
> > 
> > On Tue, May 1, 2012 at 1:13 PM, Rahul Sharma \<  
> > [rahul.sharma.coder@gmail.com](mailto:rahul.sharma.coder@gmail.com)\> wrote:
> > 
> > > Am using default configuration which uses 9300.  
> > > I am storing "amount" as a field which is a double field.
> > > 
> > > If I don't use scriptField and just use the below query then I get back  
> > > all the documents as expected.  
> > > builder.setQuery(matchAllQuery()).execute().actionGet();
> > > 
> > > But when I add scriptField its goes real searching. I tried with String  
> > > field (which is not analyzed) as well. Same result.
> > > 
> > > Thanks  
> > > Rahul
> > > 
> > > On Tue, May 1, 2012 at 1:02 PM, jagdeep singh [reach.jagdeep@gmail.com](mailto:reach.jagdeep@gmail.com)wrote:
> > > 
> > > > Which Port you bare using? 9300 or 9200?  
> > > > Please give more details about mapping and configuration.
> > > > 
> > > > On May 1, 12:16 pm, Rahul Sharma [rahul.sharma.co...@gmail.com](mailto:rahul.sharma.co...@gmail.com) wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > Stuck with a simple issue, it would be really great if any of you can  
> > > > > help  
> > > > > me out.
> > > > > 
> > > > > Trying to use a scriptField in a search query. But as I execute the  
> > > > > query,  
> > > > > it runs forever does not come out of execution. Am I doing something  
> > > > > wrong.  
> > > > > Here is the code:
> > > > > 
> > > > > SearchRequestBuilder builder = client.prepareSearch(indexName);  
> > > > > SearchResponse searchResponse =  
> > > > > builder.setQuery(matchAllQuery()).addScriptField("Amount1",  
> > > > > "doc['amount'].value").execute().actionGet();
> > > > > 
> > > > > Does not throw any exception, at the same time does not come out of  
> > > > > execution. Just hangs.
> > > > > 
> > > > > I am using elasticsearch-0.18.5
> > > > > 
> > > > > Thanks  
> > > > > Rahul

---

<div class="post-metadata">

**Author:** ![Rahul\_Sharma](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@Rahul\_Sharma](https://discuss.elastic.co/u/Rahul_Sharma)\
**Post date:** [May 3, 2012, 2:13pm UTC](https://discuss.elastic.co/t/using-script-field-in-search-query/7520/7 "2012-05-03T14:13:43Z")

</div>

I did not try in later version of 0.18 series.  
As I was upgrading so I did to the most recent which is 0.19.3

Will try it out sometime this weekend and let you know.

Thanks  
Rahul

On Wed, May 2, 2012 at 10:01 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> Can you first try and see if it happens with a later version? Its strange  
> that you get it... . If it does, can you write a simple Java program that  
> recreates the problem?
> 
> On Tue, May 1, 2012 at 10:52 PM, Rahul Sharma \<  
> [rahul.sharma.coder@gmail.com](mailto:rahul.sharma.coder@gmail.com)\> wrote:
> 
> > I could solve the issue by upgrading to 0.19.3  
> > But unfortunately I could not find a bug logged around this which got  
> > solved post 0.18.5
> > 
> > BTW, this can be replicated for addField as well.
> > 
> > On Tue, May 1, 2012 at 11:40 PM, Rahul Sharma \<  
> > [rahul.sharma.coder@gmail.com](mailto:rahul.sharma.coder@gmail.com)\> wrote:
> > 
> > > Doing some further research, I could see that the search response is  
> > > fine till
> > > 
> > > NettyTransportChannel.java --- sendResponse(Streamable message,  
> > > TransportResponseOptions options)  
> > > I assume it should return back the control after  
> > > _channel.write(buffer)_, but it does not seem like happening.
> > > 
> > > Whereas if I do regular search without addScrieptField everything works  
> > > fine\*.  
> > > Note\*: Though Scripts are working fine when its used with Facets.
> > > 
> > > Would appreciate your suggestion / pointers.
> > > 
> > > Am I doing something wrong or its a potential bug?
> > > 
> > > Thanks  
> > > Rahul
> > > 
> > > On Tue, May 1, 2012 at 1:13 PM, Rahul Sharma \<  
> > > [rahul.sharma.coder@gmail.com](mailto:rahul.sharma.coder@gmail.com)\> wrote:
> > > 
> > > > Am using default configuration which uses 9300.  
> > > > I am storing "amount" as a field which is a double field.
> > > > 
> > > > If I don't use scriptField and just use the below query then I get back  
> > > > all the documents as expected.  
> > > > builder.setQuery(matchAllQuery()).execute().actionGet();
> > > > 
> > > > But when I add scriptField its goes real searching. I tried with String  
> > > > field (which is not analyzed) as well. Same result.
> > > > 
> > > > Thanks  
> > > > Rahul
> > > > 
> > > > On Tue, May 1, 2012 at 1:02 PM, jagdeep singh [reach.jagdeep@gmail.com](mailto:reach.jagdeep@gmail.com)wrote:
> > > > 
> > > > > Which Port you bare using? 9300 or 9200?  
> > > > > Please give more details about mapping and configuration.
> > > > > 
> > > > > On May 1, 12:16 pm, Rahul Sharma [rahul.sharma.co...@gmail.com](mailto:rahul.sharma.co...@gmail.com) wrote:
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > Stuck with a simple issue, it would be really great if any of you  
> > > > > > can help  
> > > > > > me out.
> > > > > > 
> > > > > > Trying to use a scriptField in a search query. But as I execute the  
> > > > > > query,  
> > > > > > it runs forever does not come out of execution. Am I doing something  
> > > > > > wrong.  
> > > > > > Here is the code:
> > > > > > 
> > > > > > SearchRequestBuilder builder = client.prepareSearch(indexName);  
> > > > > > SearchResponse searchResponse =  
> > > > > > builder.setQuery(matchAllQuery()).addScriptField("Amount1",  
> > > > > > "doc['amount'].value").execute().actionGet();
> > > > > > 
> > > > > > Does not throw any exception, at the same time does not come out of  
> > > > > > execution. Just hangs.
> > > > > > 
> > > > > > I am using elasticsearch-0.18.5
> > > > > > 
> > > > > > Thanks  
> > > > > > Rahul

---

<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, 3:30am UTC](https://discuss.elastic.co/t/using-script-field-in-search-query/7520/8 "2017-07-06T03:30:11Z")

</div>


