PointInTime api and SearchAfter in Nest

I am working on a task in which I have to search a large number of documents in ElasticSearch using Nest client. I implemented ScrollAPI that works fine but need to use SearchAPI with SearchAfter and PointInTime as recommended. I followed the answer from @stevejgordon but I am not able to open PointInTime manually. There is always this exception in response

"message": "- Failed to make call to Elastic Search. Request failed to execute. Call: Status code 400 from: POST /IndexName/_pit. ServerError: Type: parse_exception Reason: "request body is required""

I have tried the code in the answer above and then I changed my code to create an OpenPointInTimeRequest also but got the same result.

Indices indices1 = Indices.Parse(strIndices);

IOpenPointInTimeRequest pitRequest = new OpenPointInTimeRequest(indices1);
            
OpenPointInTimeResponse pitResponse = await elasticClient.OpenPointInTimeAsync(pitRequest);

Am I doing something wrong.

One thing which I noticed that OpenPointInTimeAsync is submitting a Post request and therefore the server is complaining about the request body. Well that's my thinking someone can throw light on this.

Hi @rizhaider. That code needs one tweak, however, the error you're seeing is not what I'd expect. The PIT API is a POST but does not require a body.

The second line will need to provide a value for keep_alive, something like this:

IOpenPointInTimeRequest pitRequest = new OpenPointInTimeRequest(indices1) { KeepAlive = "1m" };

What version of Elasticsearch are you running this against?

Thanks for the reply. Even when tried with KeepAlive parameter the exception is same.

I also tried with default constructor of OpenPointInTimeRequest (i.e. without passing indices1) this time the exception is a bit difference refer below:

Status code 405 from: POST /_pit?keep_alive=1m. ServerError: Type: Reason: "Incorrect HTTP method for uri [/_pit?keep_alive=1m] and method [POST], allowed: [GET, PUT, HEAD, DELETE]\

We are running this against version 7.9.2 of Elasticsearch.

@rizhaider The Point in Time APIs were introduced in 7.10.0 of Elasticsearch. You'll need to be using at least that version for this to work.

Our nodes have data, Do you think upgrading would make any problem for us?

Upgrading to new minors versions should be safe and can be completed using a rolling upgrade. You can find full guidance in the documentation. The key step of course is backing up before you begin.

Thanks @stevejgordon for you recommendations. We upgraded Elastic cluster to 7.14.1 and everything works. Just a little issue we are facing regarding our search. We need our search to work accent insensitive e.g. If we entered data "Eric" and someone search it like "èrÏc" our result should contain "Eric". Before upgrading this was working fine but now after updating it seems that we need to do more for those cases. We also upgraded Nest Nuget to 7.14.1, but still not getting what we are expecting. For reference below is the code while creating index.

await _client.Indices.CreateAsync(index, c => c
                    .Map(x => [our-mapping])
                    .Settings(s => s.NumberOfShards(1)
                        .Analysis(x => IndexSettings.Analysis))
                );

public static IndexSettings IndexSettings => new IndexSettings
        {
            Analysis = new Analysis
            {
                Analyzers = new Analyzers(new Dictionary<string, IAnalyzer>
                {
                    ["folding"] = new CustomAnalyzer
                    {
                        Filter = new[] { "lowercase", "asciifolding" },
                        Tokenizer = "standard"
                    }
                }),
                Normalizers = new Normalizers(new Dictionary<string, INormalizer>
                {
                    ["folding"] = new CustomNormalizer
                    {
                        Filter = new[] { "lowercase", "asciifolding" }
                    }
                })
            }
        };

Hope I am clear describing my problem.