Nest Script Query example

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

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

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

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

////
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

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

So you probably want something like

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#")                
            )
       )
   )
);

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