Invalid NEST response built from a unsuccessful low level call on PUT

Hi,
I am very new to ElasticSearch and started reading about it only a day back.

The main reason as to why we chose this was to Schedule an event whenever the data chosen by the query changes.

To do this, I was trying to create a sample Watch, but with no results.
I was able to create an index and search the index. But when I try to create a Watch, I am getting the error:
Invalid NEST response built from a unsuccessful low level call on PUT.

Please find below the code:

    public static void test()
    {

        try
        {
            var settings = new ConnectionSettings(new Uri("http://localhost:9200"))
            .DefaultIndex("mypersonindex")
            .DisableDirectStreaming(true);
            var client = new ElasticClient(settings);
            

            if (!client.IndexExists("mypersonindex").Exists)
            {
                client.CreateIndex("mypersonindex");
            }
            
            var personList = new List<Person>();

            var person1 = new Person
            {
                Id = 1,
                FirstName = "First1",
                LastName = "Last1",
                Time = DateTime.Now
            };
            var person2 = new Person
            {
                Id = 2,
                FirstName = "First2",
                LastName = "Last2",
                Time = DateTime.Now
            };
            var person3 = new Person
            {
                Id = 3,
                FirstName = "First3",
                LastName = "Last3",
                Time = DateTime.Now
            };
            personList.Add(person1);
            personList.Add(person2);
            personList.Add(person3);

            var indexResponse = client.Index(person1, idx => idx.Index("mypersonindex"));
            var indexResponse1 = client.Index(person2, idx => idx.Index("mypersonindex"));
            var indexResponse2 = client.Index(person3, idx => idx.Index("mypersonindex"));

            var searchResponse = client.Search<Person>(s => s.Index("mypersonindex")
                .From(0)
                .Size(10)
                .Query(q => q
                    .Match(m => m
                        .Field(f => f.FirstName)
                        .Query("First1")
                    )
                )
            );

            var people = searchResponse.Documents; 
      // I get a successful response here - with one record

           **var responseWatch = client.PutWatch("my_watch");** 
     // this line throws the error with PUT and the below throws the error with GET
            var response = client.GetWatch("my_watch");
        }
        catch(Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        

    }

Any inputs would be really helpful!

Looking forward to the response.
Thanks!

Can you provide details of where and how you're putting the watch into Elasticsearch? Can you please also provide the .DebugInformation available on responseWatch?

Hi Russ,

Thanks for the prompt reply. I got it resolved after starting up the project fresh and installing all the items once again from scratch.

I had one question though. (Not with respect to the current question). This is with respect to the query that gets executed.

     var putWatchResponse = client.PutWatch("secondtest", p => p
                //.Active(false)
                .Trigger(t => t
                    .Schedule(s => s
                        .Interval("1m")
                )
                )
                .Input(i => i
                    .Search(s => s
                        .Request(r => r
                            .Indices("testindex")
                            .Body<Person>(b => b
                                .Query(q => q
                                    .DateRange(d => d
                                        .Field(fl => fl.Time)
                                        .GreaterThanOrEquals(DateTime.Now)
                                    )

                                )
                            )
                        )
                    )
                )
                .Condition(c => c.Always())
                .Actions(a => a
               
                .Logging("log-error", l => l
                 .Text("{{ ctx.payload.hits.total }} "))
                )

            );

Above given is the watch that I created.

                            .DateRange(d => d
                                        .Field(fl => fl.Time)
                                        .GreaterThanOrEquals(DateTime.Now)
                                    )

Above given is the part of concern.

I was under the impression that when I give DateTime.Now, each time it executes, it would take the current execution time. But seems like it is taking the value at the time the query was registered and returning same results.
Is there any way to pass in time that is not static and corresponds to the actual execution time of the query?

Thanks!

Hey Russ!

Sorry for the question. I figured it out that if we give "now" it should work!
Missed that part in the documentation.
Thanks once again!

Thanks,
Minu

Yes, "now" will work; you can also use DateMath.Now if you prefer.

You might also consider using

  • "{{ctx.trigger.triggered_time}}" - The time this watch was triggered.
  • "{{ctx.trigger.scheduled_time}}" - The time this watch was supposed to be triggered.

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