本文介绍了是否必须为要使用ElasticSearch搜索的所有索引创建POCO对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从ElasticSearch.NET开始(尝试嵌套优先).

I'm starting with ElasticSearch.NET (trying Nest first).

一个非常基本的问题:我看到的所有搜索API方法(搜索,获取等)都需要指定.NET类型.

A very basic question: all the search API methods I see (search, get, etc) require specifying a .NET type.

没有指定索引名称的方法,因此API自动推断响应类型吗?换句话说,是否必须为我们要搜索的所有索引创建POCO对象?(我从文档中了解到,ElasticSearch可以通过使用第一个文档的结构来从索引推断文档类型...)

Isn't there a way to specify an index name so the API infers the response type automatically ? In other words, is it mandatory to create POCO objects for all Indexes we intend to search ? (I understand from the documentation that ElasticSearch can infer a document type from an index by using the structure of the first document...)

推荐答案

目前不行.前面我们已经讨论了基于索引模式执行类似的操作,当将来完全删除类型时,这将有助于支持跨多个索引的协变响应.

Not currently. We've previously discussed doing something like this based on index patterns, which would be useful to support covariant responses across multiple indices when types are completely removed in the future.

否,这不是强制性的.您可以在 IElasticClient.Search< TDocument> 中为 TDocument 指定所需的任何类型,并且该类型将用于

No it's not mandatory. You can specify any type you desire for TDocument in IElasticClient.Search<TDocument> and the type will be used to

  1. 确定要反序列化每个 _source 文档的类型
  2. 通过它们到POCO属性的映射来提供对文档字段的强类型访问.

这篇关于是否必须为要使用ElasticSearch搜索的所有索引创建POCO对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 22:44