문제

Let´s say I have

class Product
{
  string name;
  List<Order> orders;
}
class Order
{
  string name;
}

If I try to map analyzers to Product name it work, but not for Order.name

//This work and adds the analyzer on the mapping list.
var resp = client.Map<Product>(map => map
                        .Properties(props => props
                            .String(s =>s
                                .Name(p => p.Name)
                                .IndexAnalyzer("normalize")
                            )
                       ));
//This does not.
var resp = client.Map<Product>(map => map
                        .Properties(props => props
                            .String(s =>s
                                .Name(p => p.orders.First().Name)
                                .IndexAnalyzer("normalize")
                            )
                       ));

Am I doing something wrong, or is this a bug?

Some more info: Those classes are just an example to show the problem. If I add [ElasticProperty(Analyzer = "normalize")] on the variable it works.

Actually the setup look something like Product Inherists from BaseProdcuts and BaseProductis is the one who has the List

도움이 되었습니까?

해결책

As answered here, .Name(p => p.Orders.First().Name) is telling ES to map the field 'Name' on the Product document. Instead, you want to map to the 'Name' field on Orders, which is an array in your Product document.

Try this instead:

client.Map<Product>(m => m
    .Properties(pp => pp
        // Map Product.Name
        .String(s => s
            .Name(p => p.Name)
            .IndexAnalyzer("normalize")
        )
        // Map Product.Orders.Name
        .Object<List<Order>>(o => o
            .Name(p => p.Orders)
            .Properties(op => op
                .String(s => s
                    .Name(os => os.First().Name)
                    .IndexAnalyzer("normalize"))))
        ));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top