3

我在 Elastic Search 中尝试对我的文档使用统计方面时遇到了一些问题。这导致了 Elastic Search google 组中的以下帖子 - 请参阅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;}
    }

但是,当我通过嵌套 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] 未嵌套..”

对此的任何想法都会很棒。

蒂姆

4

1 回答 1

3

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

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 键入为日期等的好方法。

于 2013-07-25T13:26:12.940 回答