Search code examples
c#elasticsearchnest

ElasticSearch - Insert to index with forward slash using NEST


I am currently investigating using ElasticSearch. I have been following their guides and doing some testing using the dev tools on Kibana and it seems simple enough.

Using the REST API I can index a document by sending a POST request to /recipes, and I can also index it by sending it to /recipes/cakes, but I am now having trouble replicating this behaviour via the NEST client.

I am attempting to do a bulk insert and it works fine if I just specify recipes

client.IndexMany(docs, "/recipes");

It seems to me it would make sense to be able to then also do:

client.IndexMany(docs, "/recipes/cakes");

However this throws an error: Invalid NEST response built from a successful low level call on POST: /recipes%2Fcakes/_bulk

I can see the issue is because it is url encoding the /, so what is the correct way to use an index with a / in it? I can't seem to find an answer anywhere.


Solution

  • It seems I was mistaken about how these paths work, I thought you could have several levels such as /recipes/cakes/chocolate but this would actually be to insert a document with an index recipes, type cakes and id of chocolate.

    As such I can achieve what I was trying to above by using the next parameter in the IndexMany method (TypeName type):

    client.IndexMany(docs, "recipes", "cakes");