# Nest Script Query example

**URL:** <https://discuss.elastic.co/t/nest-script-query-example/120718>\
**Category:** Elasticsearch\
**Created:** [February 20, 2018, 8:18pm UTC](https://discuss.elastic.co/t/nest-script-query-example/120718 "2018-02-20T20:18:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ESCoder](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@ESCoder](https://discuss.elastic.co/u/ESCoder)\
**Post date:** [February 20, 2018, 8:18pm UTC](https://discuss.elastic.co/t/nest-script-query-example/120718/1 "2018-02-20T20:18:28Z")

</div>

Hi,

I came across script query topic in Nest  
[https://www.elastic.co/guide/en/elasticsearch/client/net-api/6.x/script-query-usage.html](https://www.elastic.co/guide/en/elasticsearch/client/net-api/6.x/script-query-usage.html)

I'm just looking for an example on how to use this. What would be an example \_templateString in the above link which is valid?

I tried "ctx.\_source.UserIds.contains(params.param1)" and it throws a null pointer exception at "ctx". what would be an appropriate example usage.

Note: I'm using ElasticSearch 6.x

Thanks

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [February 26, 2018, 11:34pm UTC](https://discuss.elastic.co/t/nest-script-query-example/120718/2 "2018-02-26T23:34:43Z")

</div>

If you click on the `Edit` link next to the documentation example:

 ![edit_link](https://us1.discourse-cdn.com/elastic/original/3X/4/0/402a20af533d77af755098326d3bcd58bc0600cc.png)

It'll take you to the GitHub page for the documentation, and in that page is a comment that links back to the source code from which the documentation was generated e.g. for the above page

```auto
////
IMPORTANT NOTE
==============
This file has been generated from https://github.com/elastic/elasticsearch-net/tree/6.x/src/Tests/QueryDsl/Specialized/Script/ScriptQueryUsageTests.cs. 
If you wish to submit a PR for any spelling mistakes, typos or grammatical errors for this file,
please modify the original csharp file found at the link and submit the PR with that change. Thanks!
////

```

In the ScriptQueryUsageTests.cs tests, `_templateString` is

```auto
private static readonly string _templateString = "doc['numberOfCommits'].value > param1";

```

So you probably want something like

```auto
var response = client.Search<Question>(s => s
   .Query(q => q
       .Script(sq => sq
            .Source("doc['tags'].values.contains(params.param1)")
            .Params(p => p
                .Add("param1", "c#")                
            )
       )
   )
);

```

---

<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:** [March 26, 2018, 11:34pm UTC](https://discuss.elastic.co/t/nest-script-query-example/120718/3 "2018-03-26T23:34:51Z")

</div>

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