Skip to content

Nest 2.0.0 Indexing id-less object incorrectly selects PUT method, should be POST #1736

Closed
@wewebber

Description

@wewebber

If I do (in F#):

type DocType = { Id : string ; Name : string }
let myDoc = { Id = null; Name = "foo" }
client.Index(IndexRequest(DocumentPath(myDoc)))

then the request that gets generated is

PUT /doctype/doctype/
{ body }

which causes an "Invalid Request" error from ElasticSearch (2.1.1). The request should be:

POST /doctype/doctype/
{ body }

The problematic code is at line 20 of https://github.com/elastic/elasticsearch-net/blob/82c938893b2ff4ddca03a8e977ad14a16da712ba/src/Nest/Document/Single/Index/IndexRequest.cs

    protected override HttpMethod HttpMethod => ((IIndexRequest<TDocument>)this).Id 
                 == null ? HttpMethod.POST : HttpMethod.PUT;

The Id property here is Nest.Id object wrapped around the document itself. Its GetString() method will return null, but the object itself is not null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions