elasticsearch - 如何将嵌套类型与 NEST 客户端一起用于 Elastic Search

标签 elasticsearch nest

我在 Elastic Search 中尝试对我的文档使用统计方面时遇到了一些问题。这导致了 Elastic Search 谷歌群组中的以下帖子 - 请参阅 https://groups.google.com/forum/#!topic/elasticsearch/wNjrnAC_KOY .我尝试应用关于在文档中使用嵌套类型的答案中的建议,以在集合属性上提供不同的总和(参见 https://groups.google.com/forum/#!topic/elasticsearch/wNjrnAC_KOY)

也就是说,我会有很多 MyType 实例和一个 MyItem 集合。 MyItem 的某些集合将具有匹配数量的实例,即第一个文档可能具有两个 myitem 实例,数量均为 100。如果没有嵌套类型,我不相信统计方面会聚合每个数量,因为它们不是唯一的。

所以我创建了一个文档结构(类似于下面)并填充了我的索引。在填充我的索引之前,我使用了以下代码来创建一个嵌套文档。

client.MapFromAttributes<Page>(); 


[ElasticType(Name="page", DateDetection = true, NumericDetection = true, SearchAnalyzer = "standard",IndexAnalyzer = "standard")]
    public class MyType
    {
        public int TypeId { get; set; }
        public string Name { get; set; }
        public ANotherType AnotherProperty { get; set; }
        public DateTime Created { get; set; }

        [ElasticProperty(Type = FieldType.nested, Name="mycollection")]
        public List<MyItem> MyItems { get; 
    }

    public class MyItem
    {
        public decimal Amount {get;set;}
    }

但是,当我通过 nest api 运行以下查询时,我没有得到任何结果。

query.Index("pages")
        .Type("page")
        .From(0)
        .Size(100)
           .FacetStatistical("TotalAmount", x => x.Nested("donations")
           .OnField("amount")));

此外,我还通过 Chrome 插件 PostMan 尝试了以下操作:

{
   "facets": {
      "test": {
         "statistical": {
            "field": "amount"
         },
         "nested": "mycollection"
      }
   },
   "size":0
}'

并得到一个回复​​,上面写着:

"..facet 嵌套路径 [mycollection] 未嵌套.."

对此有任何想法都很好。

蒂姆

最佳答案

尝试按照以下方式映射您的对象:

client.MapFluent<MyType>(m=>m
    .MapFromAttributes()
    .NestedObject<MyItem>(no=>no
        .Name(p=>p.MyItems.First())
        .Dynamic()
        .Enabled()
        .IncludeInAll()
        .IncludeInParent()
        .IncludeInRoot()
        .MapFromAttributes()
        .Path("full")
        .Properties(pprops => pprops
            .String(ps => ps
                .Name(p => p.FirstName)
                .Index(FieldIndexOption.not_analyzed)
            )
            //etcetera
        )
    )
);

client.MapFromAttributes() 非常有限,可能会在 1.0 版本中删除。注释属性名称很棒,但很快就会限制它可以表达的内容。 mapfluent 调用中的 MapFromAttributes() 仍然是将 int 键入 int、float 键入 float、DateTime 键入日期等的好方法。

关于elasticsearch - 如何将嵌套类型与 NEST 客户端一起用于 Elastic Search,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17834767/

相关文章:

elasticsearch - ES bool和match何时应使用?

Elasticsearch document_missing_exception

search - 是否可以检查 Elasticsearch 中给定的索引和类型中是否存在documentIds列表?

c# - Elasticsearch Scroll Api-获取当前滚动位置

elasticsearch - Grafana图总数显示为列表?

docker - 使用 NEST 访问 Elasticsearch Docker 实例

nest - 使用 Elasticsearch 客户端发布原始 json

c# - 如何在ElasticSearch NEST 7.x中为具有文档ID的文档列表编制索引

c# - 为Elasticsearch日期字段提供空值

elasticsearch - 如何使用Elasticsearch 7对字段进行排序