C# Elastic Search.NET-处理多个不同名称的内部搜索
我们正在使用ElasticSearch.NETAPI 我们的查询中有多个内部点击。我们得到了所有内部点击的预期响应,但我们需要从response中获得我们班的内部点击 谁能在这方面指导我们 以下是我们的疑问-C# Elastic Search.NET-处理多个不同名称的内部搜索,c#,c#-4.0,elasticsearch,nest,C#,C# 4.0,elasticsearch,Nest,我们正在使用ElasticSearch.NETAPI 我们的查询中有多个内部点击。我们得到了所有内部点击的预期响应,但我们需要从response中获得我们班的内部点击 谁能在这方面指导我们 以下是我们的疑问- GET ai/_Users/_search { "query": { "bool": { "must": [ { "nested": { "path": "role
GET ai/_Users/_search
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "roles.permissions",
"query": {
"bool": {
"must": [
{
"match": {
"roles.permissions.pname": "p1_name"
}
}
]
}
},
"inner_hits": {
"name": "Permission1"
}
}
},
{
"nested": {
"path": "roles.permissions",
"query": {
"bool": {
"must": [
{
"match": {
"roles.permissions.pname": "p2_name"
}
}
]
}
},
"inner_hits": {
"name": "Permission2"
}
}
}
]
}
},
"_source": "false"
}
我们创建了以下类来处理弹性响应-
public class sharedData
{
public Nullable<int> total { get; set; }
public Nullable<int> successful { get; set; }
public Nullable<int> failed { get; set; }
}
public class HitsData
{
public string _index { get; set; }
public string _type { get; set; }
public string _id { get; set; }
public double _score { get; set; }
public Object _source { get; set; }
public inner_hits inner_hits { get; set; }
}
public class inner_hits
{
public Permission1 Permission1 { get; set; }
}
public class Permission1
{
public Nullable<int> took { get; set; }
public bool timed_out { get; set; }
public sharedData _shards { get; set; }
public Hits hits { get; set; }
public Aggregations aggregations { get; set; }
}
public class Hits
{
public int total { get; set; }
public Nullable<double> max_score { get; set; }
public HitsData[] hits { get; set; }
}
public class Aggregations
{
public ChildObjectAggregations childObjectAggregations { get; set; }
}
public class ChildObjectAggregations
{
public int doc_count { get; set; }
}
public class ResultElasticData
{
public Nullable<int> took { get; set; }
public bool timed_out { get; set; }
public sharedData _shards { get; set; }
public Hits hits { get; set; }
public Aggregations aggregations { get; set; }
}
公共类共享数据
{
公共可为空的总计{get;set;}
公共可空成功{get;set;}
公共可为Null失败{get;set;}
}
公共类HitsData
{
公共字符串_索引{get;set;}
公共字符串_type{get;set;}
公共字符串_id{get;set;}
公共双倍{get;set;}
公共对象_源{get;set;}
公共内部点击内部点击{get;set;}
}
公共类内部搜索
{
公共权限1权限1{get;set;}
}
公共类许可证1
{
公共可为Null的属性{get;set;}
公共布尔超时{get;set;}
公共共享数据_碎片{get;set;}
公共点击次数{get;set;}
公共聚合{get;set;}
}
公开课热门
{
公共整数总计{get;set;}
公共可为空的最大分数{get;set;}
公共HitsData[]命中{get;set;}
}
公共类聚合
{
公共ChildObjectAggregations ChildObjectAggregations{get;set;}
}
公共类ChildObjectAggregations
{
公共整数docu计数{get;set;}
}
公共类resultlasticata
{
公共可为Null的属性{get;set;}
公共布尔超时{get;set;}
公共共享数据_碎片{get;set;}
公共点击次数{get;set;}
公共聚合{get;set;}
}
下面是我们从弹性响应中获取内部点击的代码-
ElasticsearchResponse<ResultElasticData> x = objElasticsearchClient.Search<ResultElasticData>("ionai", "IACM.AI.BOD.Application_Users", sJSONQuery);
if (x.Response != null && x.Success == true && x.HttpStatusCode == 200)
{
foreach (HitsData hit in x.Response.hits.hits)
{
foreach (HitsData innerhit in hit.inner_hits.Permission1.hits.hits)
{
innerhit._source.ToString();
}
}
}
ElasticsearchResponse x=objElasticsearchClient.Search(“ionai”、“IACM.AI.BOD.Application\u Users”、sJSONQuery);
if(x.Response!=null&&x.Success==true&&x.HttpStatusCode==200)
{
foreach(x.Response.hits.hits中的HitsData hit)
{
foreach(HitsData innerhit in hit.inner_hits.Permission1.hits.hits)
{
innerhit._source.ToString();
}
}
}
这里的问题是,我们只能为名为“Permission1”的内部命中获取内部命中。这是因为我们只为Permission1创建了类
所以我们的问题是,如果我们有多个名字不同的内部点击,那么如何获得所有的内部点击?我们不能预先为内部点击创建类,因为我们不知道会有多少内部点击
非常感谢您的指导
谢谢