elasticsearch 将复制到的属性/Fluent映射与嵌套相结合,elasticsearch,nest,elasticsearch,Nest" /> elasticsearch 将复制到的属性/Fluent映射与嵌套相结合,elasticsearch,nest,elasticsearch,Nest" />

elasticsearch 将复制到的属性/Fluent映射与嵌套相结合

elasticsearch 将复制到的属性/Fluent映射与嵌套相结合,elasticsearch,nest,elasticsearch,Nest,我想在Nest中使用“复制到”功能。我已经读到我需要使用fluent映射() 是否可以使用基于属性的映射,然后在其上使用fluent映射来添加副本?如果有,有什么例子吗?我很难找到答案 要复制到的字段在模型类中不存在。我只想在elasticsearch中搜索它 [ElasticType(IdProperty = "CustomerId", Name = "customer_search")] public class CustomerSearchResult : BindableBase {

我想在Nest中使用“复制到”功能。我已经读到我需要使用fluent映射()

是否可以使用基于属性的映射,然后在其上使用fluent映射来添加副本?如果有,有什么例子吗?我很难找到答案

要复制到的字段在模型类中不存在。我只想在elasticsearch中搜索它

[ElasticType(IdProperty = "CustomerId", Name = "customer_search")]
public class CustomerSearchResult : BindableBase
{
    [ElasticProperty(Name = "customer_id", Index = FieldIndexOption.NotAnalyzed, Type = FieldType.String)]
    public int CustomerId { get; set; }
    [ElasticProperty(Name = "account_type", Index = FieldIndexOption.NotAnalyzed, Type = FieldType.String)]
    public string AccountType { get; set; }
    [ElasticProperty(Name = "short_name", Index = FieldIndexOption.NotAnalyzed, Type = FieldType.String)]
    public string ShortName { get; set; }
    [ElasticProperty(Name = "legacy_name", Index = FieldIndexOption.NotAnalyzed, Type = FieldType.String)]
    public string LegacyName { get; set; }
    [ElasticProperty(Name = "legacy_contact_name", Index = FieldIndexOption.NotAnalyzed, Type = FieldType.String)]
    public string LegacyContactName { get; set; }
    [ElasticProperty(Name = "city", Index = FieldIndexOption.NotAnalyzed, Type = FieldType.String)]
    public string City { get; set; }
    [ElasticProperty(Name = "state_abbreviation", Index = FieldIndexOption.NotAnalyzed, Type = FieldType.String)]
    public string StateAbbreviation { get; set; }
    [ElasticProperty(Name = "country", Index = FieldIndexOption.NotAnalyzed, Type = FieldType.String)]
    public string Country { get; set; }
    [ElasticProperty(Name = "postal_code", Index = FieldIndexOption.NotAnalyzed, Type = FieldType.String)]
    public string PostalCode { get; set; }
}

在上面的类中,我想使用ShortName、LegacyName和LegacyContactName并将其复制到一个名为“search”的字段中,该字段将是一个分析字段。

类似于以下内容的内容应该可以完成此操作

void Main()
{
    var settings = new ConnectionSettings(new Uri("http://localhost:9200"));
    var connection = new InMemoryConnection(settings);
    var client = new ElasticClient(connection: connection);


    var indexResponse = client.CreateIndex("customer_searches", c => c
        .AddMapping<CustomerSearchResult>(m => m
            .MapFromAttributes()
            .Properties(p => p
                .String(s => s.Name("short_name").CopyTo("search").Index(FieldIndexOption.NotAnalyzed))
                .String(s => s.Name("legacy_name").CopyTo("search").Index(FieldIndexOption.NotAnalyzed))
                .String(s => s.Name("legacy_contact_name").CopyTo("search").Index(FieldIndexOption.NotAnalyzed))
                .String(s => s.Name("search").Index(FieldIndexOption.Analyzed))
            )
        )
    );

    Console.WriteLine(Encoding.UTF8.GetString(indexResponse.RequestInformation.Request));
}

Properties()
的调用将覆盖默认约定和属性映射,因此您需要在那里指定字段
也未进行分析。

类似于以下内容的操作可以做到这一点

void Main()
{
    var settings = new ConnectionSettings(new Uri("http://localhost:9200"));
    var connection = new InMemoryConnection(settings);
    var client = new ElasticClient(connection: connection);


    var indexResponse = client.CreateIndex("customer_searches", c => c
        .AddMapping<CustomerSearchResult>(m => m
            .MapFromAttributes()
            .Properties(p => p
                .String(s => s.Name("short_name").CopyTo("search").Index(FieldIndexOption.NotAnalyzed))
                .String(s => s.Name("legacy_name").CopyTo("search").Index(FieldIndexOption.NotAnalyzed))
                .String(s => s.Name("legacy_contact_name").CopyTo("search").Index(FieldIndexOption.NotAnalyzed))
                .String(s => s.Name("search").Index(FieldIndexOption.Analyzed))
            )
        )
    );

    Console.WriteLine(Encoding.UTF8.GetString(indexResponse.RequestInformation.Request));
}

调用
Properties()
会覆盖默认约定和属性映射,因此您需要指定字段
也不在那里进行分析。

嵌套2呢?有没有一种方法可以从属性映射装饰器中实现这一点?很多属性都是通过映射属性公开的,但不是全部;通常,如果一个映射属性拥有多个自己的属性,例如
规范
(可以启用/禁用和惰性/急切加载),则只能通过fluent mapping api进行设置。类似地,多字段只能通过fluent映射定义。NEST 2.x中的属性属性在很大程度上与NEST 1.x中的属性相似,通常与Elasticsearch中的更改不同。看看Nest 2怎么样?有没有一种方法可以从属性映射装饰器中实现这一点?很多属性都是通过映射属性公开的,但不是全部;通常,如果一个映射属性拥有多个自己的属性,例如
规范
(可以启用/禁用和惰性/急切加载),则只能通过fluent mapping api进行设置。类似地,多字段只能通过fluent映射定义。NEST 2.x中的属性属性在很大程度上与NEST 1.x中的属性相似,通常与Elasticsearch中的更改不同。看看