1
votes

I want to configurate NEST from c# code When I use Kibana command GET /_cat/indices?v

I get this result:

enter image description here

My test index is "customer"

I'm using Elasticsearch.Net and NEST: the .NET clients [6.x] Elastic "6.5.4", Now this is how I configurate on C#:

  var settings = new ConnectionSettings(new Uri("http://localhost:9200"))
.DefaultIndex("customer");

        var client = new ElasticClient(settings);



        var newCustomer = new Customer
        {
            name = "test_name",
            OS = "test_os",
            script = "test_script"
        };


        var indexResponse = client.IndexDocument(newCustomer);

and I get an error:

Invalid NEST response built from a unsuccessful low level call on POST: /customer/customer

why does it build request to /customer/customer ??? What am I configurating wrong?

Error message:

Invalid NEST response built from a unsuccessful low level call on POST: /customer/customer Audit trail of this API call: - BadResponse: Node: http://localhost:9200/ Took: 00:00:00.2817669 OriginalException: Elasticsearch.Net.ElasticsearchClientException: Удаленный сервер возвратил ошибку: (400) Недопустимый запрос.. Call: Status code 400 from: POST /customer/customer. ServerError: Type: illegal_argument_exception Reason: "Rejecting mapping update to [customer] as the final mapping would have more than 1 type: [_doc, customer]" ---> System.Net.WebException: Удаленный сервер возвратил ошибку: (400) Недопустимый запрос.

2

2 Answers

3
votes

You have already a mapping in ES and the document you want to index doesnot match with it.

-1
votes

why does it build request to /customer/customer ??? What am I configurating wrong?

It builds it to customer (index) and customer (type) because

  1. the index request does not specify an index into which the document should be indexed, so the request uses the configured default index from ConnectionSettings
  2. the index request does not specify a type for the document so NEST infers the type name from the POCO type name, by lowercasing it.

If you want to set a default type name for all POCOs, you can use

var settings = new ConnectionSettings(new Uri("http://localhost:9200"))
    .DefaultIndex("customer")
    .DefaultTypeName("_doc"); // <--- type name used for all POCOs