elasticsearch,nest,C#,elasticsearch,Nest" /> elasticsearch,nest,C#,elasticsearch,Nest" />

C# 如何用C区分ElasticSearch中的字段(搜索结果中有多个重复项)?

C# 如何用C区分ElasticSearch中的字段(搜索结果中有多个重复项)?,c#,elasticsearch,nest,C#,elasticsearch,Nest,我试图从elasticsearch服务器获取/搜索结果。但我只有获取权限,所以我无法将一些映射索引放入ES服务器或更改ElasticSarch中的任何配置 …/testindex/doc/\u search?q=country\u代码:99&size=5000&pretty 我尝试创建新索引,但已经失败了,因为我没有任何权限 我还尝试了以下代码: 并且不返回存储桶或文档计数:[0] 我在ElasticSearch中也需要伪SQL代码 从testindex中选择*不同的所有者代码,其中国家/地区代

我试图从elasticsearch服务器获取/搜索结果。但我只有获取权限,所以我无法将一些映射索引放入ES服务器或更改ElasticSarch中的任何配置

…/testindex/doc/\u search?q=country\u代码:99&size=5000&pretty

我尝试创建新索引,但已经失败了,因为我没有任何权限

我还尝试了以下代码:

并且不返回存储桶或文档计数:[0]

我在ElasticSearch中也需要伪SQL代码

从testindex中选择*不同的所有者代码,其中国家/地区代码=99

所以我应该得到这些结果Mike-Brown-555-99,John-Smith-444-99。。并忽略具有相同所有者代码的其他结果。名称和/或姓氏字段不同并不重要。我想区分所有者代码字段并搜索countryCode字段。在SQL查询中很容易做到,但在ElasticSearchV6.x中我非常困惑


提前谢谢

您能否共享result.DebugInformation中的信息以及您使用的elasticsearch和NEST的哪个版本?您能否共享映射到。还可以共享CustomDToC类,非常确定您的类与es映射不匹配。
{
    "took": 58,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 3,
        "max_score": 0.2876821,
        "hits": [ // Above result numbers may not be correct!
            {
                "_index": "testindex",
                "_type": "doc",
                "_id": "3",
                "_score": 0.2876821,
                "_source": {
                    "name": "George",
                    "lastname": "Bush",
                    "owner_code": "555"
                    "country_code": "99"
                }
            },
            {
                "_index": "testindex",
                "_type": "doc",
                "_id": "2",
                "_score": 0.2876821,
                "_source": {
                    "name": "John",
                    "lastname": "Smith",
                    "owner_code": "444"
                    "country_code": "99"
                }
            },
            {
                "_index": "testindex",
                "_type": "doc",
                "_id": "1",
                "_score": 0.28582606,
                "_source": {
                    "name": "Mike",
                    "lastname": "Brown",
                    "owner_code": "555"
                    "country_code": "99"
                }
            }
        ]
    }
}
[JsonObject]
class CustomDTO
{
        [JsonProperty("name")]
        public string name { get; set; }
        [JsonProperty("lastname")]
        public string lastname { get; set; }
        [JsonProperty("owner_code")]
        public string owner_code { get; set; }
        [JsonProperty("country_code")]
        public string country_code { get; set; }
}
// ElasticSearch v6.x
var result = _client.Search<CustomDTO>(s => s
    .Index("testindex")
    .Type("doc")
    .From(0)
    .Size(5000)
    .Aggregations(a => a
        .Terms("my_terms_agg", t => t
            .Field("owner_code.keyword")
            .Size(2000)
        )
    )
    .Query(q => q.QueryString(qs => qs
         .Field(f => f.country_code)
         .Query("99"))));
{ 
   { 
      "name":"Mike",
      "lastname":"Brown",
      "owner_code":"555",
      "country_code":"99"
   },
   { 
      "name":"John",
      "lastname":"Smith",
      "owner_code":"555",
      "country_code":"99"
   }
}