【问题标题】:Does ElasticSearch support dynamic fields using ElasticProperty?ElasticSearch 是否支持使用 ElasticProperty 的动态字段?
【发布时间】:2015-09-10 22:24:41
【问题描述】:

我正在使用 Nest 在 C# 中访问 ElasticSearch。我已经建立了一个结构,它指定 ElasticProperty 属性来定义要存储/索引/排序/等的字段。这一切都很好。

现在我有了保存和搜索额外“动态”数据的新要求...

这个新数据的工作方式如下:我的数据结构(项目)可以有多个关联的字符串标签,分类到不同的部分。所以单个项目可能有Section1.Label1, Section1.Label2, Section2.Label1,Section3.Label4

如果我将它存储在 c# 中,我可能会使用 Dictionary<string, List<string>> 来存储它。但在 ElasticSearch 中,我还需要能够搜索这些标签,例如“给我所有具有 Section2.Label1 的项目”。不需要分析标签(只是存在与否)。

感谢您提供的任何线索,告诉 Nest 如何存储此类数据字段。

更新 #1:看起来我可能正在查看某种类型的 [ElasticProperty(Type = FieldType.Nested)] 而不是动态映射。我应该只使用标记为嵌套类型的Dictionary<string, List<string>> 吗?

【问题讨论】:

  • 为此我认为你必须使用某种嵌套对象

标签: c# dynamic data-structures elasticsearch nest


【解决方案1】:

看起来这行得通...

    [ElasticProperty(Index = FieldIndexOption.NotAnalyzed, Store = true, Type = FieldType.Nested, OmitNorms = true, IncludeInAll = false)]
    public Dictionary<string, List<string>> MyLabels { get; set; }

在 ElasticSearch 方面,它是一个包含字符串数组的 Map。我仍然需要在搜索方面进行工作以提出一个查询,该查询将确定特定映射中特定标签的存在,但这应该很简单(敲木头)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-29
    • 2014-12-23
    • 2016-03-04
    • 1970-01-01
    • 2019-04-19
    • 1970-01-01
    • 2021-12-14
    相关资源
    最近更新 更多