# PointInTime api and SearchAfter in Nest

**URL:** <https://discuss.elastic.co/t/pointintime-api-and-searchafter-in-nest/283908>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [September 10, 2021, 6:48pm UTC](https://discuss.elastic.co/t/pointintime-api-and-searchafter-in-nest/283908 "2021-09-10T18:48:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rizhaider](https://avatars.discourse-cdn.com/v4/letter/r/e19b73/32.png) [@rizhaider](https://discuss.elastic.co/u/rizhaider)\
**Post date:** [September 10, 2021, 6:48pm UTC](https://discuss.elastic.co/t/pointintime-api-and-searchafter-in-nest/283908/1 "2021-09-10T18:48:46Z")

</div>

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](https://discuss.elastic.co/t/point-in-time-api-and-search-after-net-nest/278572) 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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![stevejgordon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stevejgordon/32/80912_2.png) [@stevejgordon](https://discuss.elastic.co/u/stevejgordon)\
**Post date:** [September 12, 2021, 6:35pm UTC](https://discuss.elastic.co/t/pointintime-api-and-searchafter-in-nest/283908/2 "2021-09-12T18:35:36Z")

</div>

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:

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

```

What version of Elasticsearch are you running this against?

---

<div class="post-metadata">

**Author:** ![rizhaider](https://avatars.discourse-cdn.com/v4/letter/r/e19b73/32.png) [@rizhaider](https://discuss.elastic.co/u/rizhaider)\
**Post date:** [September 13, 2021, 2:40pm UTC](https://discuss.elastic.co/t/pointintime-api-and-searchafter-in-nest/283908/3 "2021-09-13T14:40:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stevejgordon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stevejgordon/32/80912_2.png) [@stevejgordon](https://discuss.elastic.co/u/stevejgordon)\
**Post date:** [September 13, 2021, 2:58pm UTC](https://discuss.elastic.co/t/pointintime-api-and-searchafter-in-nest/283908/4 "2021-09-13T14:58:36Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![rizhaider](https://avatars.discourse-cdn.com/v4/letter/r/e19b73/32.png) [@rizhaider](https://discuss.elastic.co/u/rizhaider)\
**Post date:** [September 13, 2021, 3:03pm UTC](https://discuss.elastic.co/t/pointintime-api-and-searchafter-in-nest/283908/5 "2021-09-13T15:03:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stevejgordon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stevejgordon/32/80912_2.png) [@stevejgordon](https://discuss.elastic.co/u/stevejgordon)\
**Post date:** [September 13, 2021, 3:08pm UTC](https://discuss.elastic.co/t/pointintime-api-and-searchafter-in-nest/283908/6 "2021-09-13T15:08:05Z")

</div>

Upgrading to new minors versions should be safe and can be completed using a rolling upgrade. You can find full guidance in [the documentation](https://www.elastic.co/guide/en/elasticsearch/reference/7.14/setup-upgrade.html). The key step of course is backing up before you begin.

---

<div class="post-metadata">

**Author:** ![rizhaider](https://avatars.discourse-cdn.com/v4/letter/r/e19b73/32.png) [@rizhaider](https://discuss.elastic.co/u/rizhaider)\
**Post date:** [September 15, 2021, 8:28pm UTC](https://discuss.elastic.co/t/pointintime-api-and-searchafter-in-nest/283908/7 "2021-09-15T20:28:27Z")

</div>

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.

```auto
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.

---

<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:** [October 13, 2021, 8:28pm UTC](https://discuss.elastic.co/t/pointintime-api-and-searchafter-in-nest/283908/8 "2021-10-13T20:28:32Z")

</div>

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