简体   繁体   English

ElasticSearch-使用NEST插入带有正斜杠的索引

[英]ElasticSearch - Insert to index with forward slash using NEST

I am currently investigating using ElasticSearch. 我目前正在调查使用ElasticSearch。 I have been following their guides and doing some testing using the dev tools on Kibana and it seems simple enough. 我一直在遵循他们的指南,并使用Kibana上的开发工具进行了一些测试,这似乎很简单。

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. 使用REST API,我可以通过将POST请求发送到/recipes来索引文档,也可以通过将它发送到/recipes/cakes来索引文档,但是现在我很难通过NEST客户端复制此行为。

I am attempting to do a bulk insert and it works fine if I just specify recipes 我正在尝试进行批量插入,如果我仅指定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 但是,这将引发错误: 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? 我可以看到问题是因为它是对/ url编码的,所以使用带/的索引的正确方法是什么? I can't seem to find an answer anywhere. 我似乎在任何地方都找不到答案。

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 . 看来我对这些路径的工作方式有误,我认为您可能有几个级别,例如/recipes/cakes/chocolate但这实际上是插入带有索引recipes ,类型cakeschocolate id的文档。

As such I can achieve what I was trying to above by using the next parameter in the IndexMany method ( TypeName type ): 这样,我可以通过使用IndexMany方法( TypeName type )中的下一个参数来实现上面的目标:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM