# When getting a CompletedReindexResponse, I'm receiving an interesting message: Invalid NEST response built from a null ApiCall which is highly exceptional, please open a bug if you see this

**URL:** <https://discuss.elastic.co/t/when-getting-a-completedreindexresponse-im-receiving-an-interesting-message-invalid-nest-response-built-from-a-null-apicall-which-is-highly-exceptional-please-open-a-bug-if-you-see-this/248164>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [September 10, 2020, 12:00pm UTC](https://discuss.elastic.co/t/when-getting-a-completedreindexresponse-im-receiving-an-interesting-message-invalid-nest-response-built-from-a-null-apicall-which-is-highly-exceptional-please-open-a-bug-if-you-see-this/248164 "2020-09-10T12:00:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![CollabcoAndy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/collabcoandy/32/75362_2.png) [@CollabcoAndy](https://discuss.elastic.co/u/CollabcoAndy)\
**Post date:** [September 10, 2020, 12:00pm UTC](https://discuss.elastic.co/t/when-getting-a-completedreindexresponse-im-receiving-an-interesting-message-invalid-nest-response-built-from-a-null-apicall-which-is-highly-exceptional-please-open-a-bug-if-you-see-this/248164/1 "2020-09-10T12:00:44Z")

</div>

Hi all,

I'm exploring the NEST client currently and followed the code for ReindexOnServer here:  
[https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/reindexing-documents.html](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/reindexing-documents.html)

I have followed the code pretty exactly, to not wait for completion, to pick up the task and check for completion in a loop:

```auto
         var reindexResponse = Client.ReindexOnServer(r => r
                .Source(s => s
                    .Index(oldId)
                )
                .Destination(d => d
                    .Index(this.UniqueId)
                )
                .WaitForCompletion(false)
);

                var taskId = reindexResponse.Task;
                var taskResponse = Client.Tasks.GetTask(taskId);

                while (!taskResponse.Completed)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(20));
                    taskResponse = Client.Tasks.GetTask(taskId);
                }

                var completedReindexResponse = taskResponse.GetResponse<ReindexOnServerResponse>();
                if (!completedReindexResponse.IsValid)
                {
                    throw new Exception($"Error reindexing: {completedReindexResponse.DebugInformation}");
                }

```

completedReindexResponse is coming back with isValid = false and the error I mentioned above in the debugInformation

> Invalid NEST response built from a null ApiCall which is highly exceptional, please open a bug if you see this

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![CollabcoAndy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/collabcoandy/32/75362_2.png) [@CollabcoAndy](https://discuss.elastic.co/u/CollabcoAndy)\
**Post date:** [September 10, 2020, 8:43pm UTC](https://discuss.elastic.co/t/when-getting-a-completedreindexresponse-im-receiving-an-interesting-message-invalid-nest-response-built-from-a-null-apicall-which-is-highly-exceptional-please-open-a-bug-if-you-see-this/248164/2 "2020-09-10T20:43:16Z")

</div>

Full code for my method

```auto
    public override async Task ReindexAsync()
    {

        var oldId = this.UniqueId;
        this.UniqueId = Guid.NewGuid().ToString("N");
        var result = await Client.Indices.RefreshAsync(oldId);
        var createIdxResult = await Client.Indices.CreateAsync(
            this.UniqueId,
            i =>
                i
                    .Settings(s => CommonElasticIndexDescriptor(s, this.Alpha2LanguageCode))
                    .Map<SearchableCmsPageItem>(m => m
                    .AutoMap()

                )
            );

        if (result.IsValid && createIdxResult.IsValid)
        {
            var reindexResponse = Client.ReindexOnServer(r => r
            .Source(s => s
                .Index(oldId)
            )
            .Destination(d => d
                .Index(this.UniqueId)
            )
            .WaitForCompletion(false)
);

            var taskId = reindexResponse.Task;
            var taskResponse = Client.Tasks.GetTask(taskId);

            while (!taskResponse.Completed)
            {
                Thread.Sleep(TimeSpan.FromSeconds(20));
                taskResponse = Client.Tasks.GetTask(taskId);
            }

            var completedReindexResponse = taskResponse.GetResponse<ReindexOnServerResponse>();
            if (!completedReindexResponse.IsValid)
            {
                throw new Exception($"Error reindexing: {completedReindexResponse.DebugInformation}");
            }
            var realiasResult = await Client.Indices.BulkAliasAsync(b => b
                   .Remove(r => r
                       .Alias(this.Alias)
                       .Index(oldId))
                   .Add(a => a
                       .Alias(this.Alias)
                       .Index(this.UniqueId)));
            if (!realiasResult.IsValid)
            {
                throw new Exception($"Error swapping index alias from {oldId} to {this.UniqueId} indexes");
                // what to do here? Delete the new index and pass retry logic up or retry here?
            }
            else
            {
                try
                {
                    var delRes = Client.Indices.Delete(oldId);
                    if (!delRes.IsValid)
                    {
                        throw new Exception($"Failed to delete Index {oldId}");
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

        }
    }

```

---

<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:** [September 11, 2020, 3:14am UTC](https://discuss.elastic.co/t/when-getting-a-completedreindexresponse-im-receiving-an-interesting-message-invalid-nest-response-built-from-a-null-apicall-which-is-highly-exceptional-please-open-a-bug-if-you-see-this/248164/3 "2020-09-11T03:14:00Z")

</div>

The `IsValid` response of an `IResponse` deserialized with `.GetResponse<T>()` on a `GetTaskResponse` (that's a bit of a mouthful 😃) cannot be used or relied upon because it uses parts of the HTTP response in determining validity, such as HTTP status code, and the HTTP response details available relate to the `GetTaskResponse`.

The XML documentation comment on `GetResponse<T>` mentions this

> <https://github.com/elastic/elasticsearch-net/blob/57965e9561acfe3946c633347f9c970b001c51a5/src/Nest/Cluster/TaskManagement/GetTask/GetTaskResponse.cs#L21-L26>

---

<div class="post-metadata">

**Author:** ![CollabcoAndy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/collabcoandy/32/75362_2.png) [@CollabcoAndy](https://discuss.elastic.co/u/CollabcoAndy)\
**Post date:** [September 11, 2020, 7:40am UTC](https://discuss.elastic.co/t/when-getting-a-completedreindexresponse-im-receiving-an-interesting-message-invalid-nest-response-built-from-a-null-apicall-which-is-highly-exceptional-please-open-a-bug-if-you-see-this/248164/4 "2020-09-11T07:40:04Z")

</div>

Fantastic! Thanks, that makes sense!

---

<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:** [September 11, 2020, 10:02am UTC](https://discuss.elastic.co/t/when-getting-a-completedreindexresponse-im-receiving-an-interesting-message-invalid-nest-response-built-from-a-null-apicall-which-is-highly-exceptional-please-open-a-bug-if-you-see-this/248164/5 "2020-09-11T10:02:32Z")

</div>

No worries!

---

<div class="post-metadata">

**Author:** ![CollabcoAndy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/collabcoandy/32/75362_2.png) [@CollabcoAndy](https://discuss.elastic.co/u/CollabcoAndy)\
**Post date:** [September 11, 2020, 11:24am UTC](https://discuss.elastic.co/t/when-getting-a-completedreindexresponse-im-receiving-an-interesting-message-invalid-nest-response-built-from-a-null-apicall-which-is-highly-exceptional-please-open-a-bug-if-you-see-this/248164/6 "2020-09-11T11:24:54Z")

</div>

OK, that works like a charm now i understand it, but it's not intuitive. I understand sometimes design decisions need to be made that aren't optimal, but combined with sparse documentation on the nest client this will throw noobs like me who are wanting to do something basic like reindex in .Net and will drive people from using the client. Please accept this as constructive criticism, I'm really keen to drive adoption of elastic search in our platform (not just for search) and an continuing to champion this. I certainly appreciate the quick and constructive help I've gotten from the elastic team while I've been exploring your nest client and elastic in general! 🙂

---

<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:** [September 14, 2020, 4:53am UTC](https://discuss.elastic.co/t/when-getting-a-completedreindexresponse-im-receiving-an-interesting-message-invalid-nest-response-built-from-a-null-apicall-which-is-highly-exceptional-please-open-a-bug-if-you-see-this/248164/7 "2020-09-14T04:53:54Z")

</div>

Thank you for raising, I genuinely appreciate the feedback! :elasticheart:

I'd like to explain how the design has come about, as I think it'd shed some light on why it currently is as it is. I agree that it could be more intuitive in the future.

The `GetResponse<T>()` method was introduced in 7.2.0 in [PR #3966](https://github.com/elastic/elasticsearch-net/pull/3966). Since it's possible that `T` could be any type of response that currently exists, or might exist in the future for a new task based API, it was decided to constrain `T` to types that implement `IResponse`, the common interface for responses.

A downside in taking this approach is that `IResponse` contains some members that won't be valid to be used in the `GetResponse<T>()` context, specifically, those that derive their values from properties of the underlying HTTP response, such as status codes, headers, etc. such as `IsValid`, whose default implementation checks HTTP status codes

> <https://github.com/elastic/elasticsearch-net/blob/a6025ccc4836ce1084d988d99f4bcf6769156951/src/Nest/CommonAbstractions/Response/ResponseBase.cs#L93-L100>

Another approach to tackling this would be to split the `IResponse` (and `IElasticsearchResponse` interface that it implements) to separate out members that derive their values from properties of the underlying response from those that don't, such that we have an interface that can be used to represent a response for `GetResponse<T>()` and one to use for representing an _overall_ response from Elasticsearch. This might be an approach to consider for the next major version, but we wouldn't be able to make this change within 7.2.0 or the 7.x lineage because it would introduce binary compatibility breaking changes, something that we really want to avoid within a major version because of the impact it has on packages that take a dependency on the client packages.

---

<div class="post-metadata">

**Author:** ![CollabcoAndy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/collabcoandy/32/75362_2.png) [@CollabcoAndy](https://discuss.elastic.co/u/CollabcoAndy)\
**Post date:** [September 14, 2020, 7:59am UTC](https://discuss.elastic.co/t/when-getting-a-completedreindexresponse-im-receiving-an-interesting-message-invalid-nest-response-built-from-a-null-apicall-which-is-highly-exceptional-please-open-a-bug-if-you-see-this/248164/8 "2020-09-14T07:59:22Z")

</div>

Hi Russ, thanks for the outline, can totally appreciate the decisions made. 🙂 😄

---

<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 12, 2020, 7:59am UTC](https://discuss.elastic.co/t/when-getting-a-completedreindexresponse-im-receiving-an-interesting-message-invalid-nest-response-built-from-a-null-apicall-which-is-highly-exceptional-please-open-a-bug-if-you-see-this/248164/9 "2020-10-12T07:59:34Z")

</div>

Closed on October 12, 2020, 7:59am UTC

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