[英]Indexing dynamic objects in elasticsearch nest
Elastic search generally works with pre-defined classes . 弹性搜索通常适用于预定义的类。 How do I work with dynamic classes.
我如何使用动态类。 eg: Suppose I want to search a particular field then
例如:假设我想搜索一个特定的字段
var result = clientConnection.Search<**TicketData**>(
s => s
.Aggregations(
a => a
.DateRange(
"L1", d => d
.Field(p => p.timestamp)
.Ranges(
r => r.To("2016-10-09T15:01:06+00:00"),
r => r.From("2016-09-27T02:09:17+00:00")
)
)
)
);
Here the ticketdata class has to be defined beforehand. 在这里,ticketdata类必须预先定义。 Can we have something like
我们可以有类似的东西吗
var result = clientConnection.Search<ANYDYNAMICCLASS>(s => s
.Aggregations(a => a
.DateRange("L1", d => d
.Field(p => p.timestamp)
.Ranges(
r => r.To("2016-10-09T15:01:06+00:00"),
r => r.From("2016-09-27T02:09:17+00:00")
)
)
)
);
Can a dynamic class/ dynamic object work with this ? 动态类/动态对象可以与此一起工作吗? please give an example how it can be done.
请举一个例子。
Elasticsearch works with JSON documents, it's not tied to C# POCOs. Elasticsearch适用于JSON文档,它不与C#POCO绑定。 With a strongly typed language like C# however, it makes a lot of sense to model documents in Elasticsearch as POCOs in your application but you don't have to.
但是,使用像C#这样的强类型语言,在Elasticsearch中将文档建模为应用程序中的POCO非常有意义,但是您不必这样做。
For example, we could use dynamic
as the document type to search, and use the .Index()
and .Type()
methods to specify the indices and types, respectively 例如,我们可以使用
dynamic
作为搜索的文档类型,并使用.Index()
和.Type()
方法分别指定索引和类型。
var result = client.Search<dynamic>(s => s
.Index("index-name")
.Type("type-name")
.Aggregations(a => a
.DateRange("L1", d => d
.Field("timestamp")
.Ranges(
r => r.To("2016-10-09T15:01:06+00:00"),
r => r.From("2016-09-27T02:09:17+00:00")
)
)
)
); );
You can also work with Elasticsearch.Net directly through the .LowLevel
property on the client and work with streams, bytes or strings as well. 您还可以直接通过客户端上的
.LowLevel
属性使用Elasticsearch.Net,还可以使用流,字节或字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.