简体   繁体   English

使用 NEST 使用 ElasticSearch 2.x 搜索多种类型时,如何获得混合结果?

[英]How do you get mixed results when searching multiple types with ElasticSearch 2.x using NEST?

I'm pretty new to Elastic Search and stumbled upon this issue.我对 Elastic Search 很陌生,偶然发现了这个问题。 When searching multiple document types from the same index, the types are getting appended in the result documents set instead of being default sorted by boosted field.从同一索引中搜索多个文档类型时,这些类型会附加到结果文档集中,而不是默认按提升字段排序。 My document types shares the same fields.我的文档类型共享相同的字段。

This is my search query:这是我的搜索查询:

        var response = await client.SearchAsync<ProductListResponse>(s => s
            .Type("product,productbundle")
            .Index(index)
            .From(from)
            .Size(size)
            .Query(fsq => fsq
                .FunctionScore(c => c.Query(q => q
                    .MultiMatch(m => m.Query(request.Query)
                    .Fields(f => f
                        .Field(n => n.Name, 100.0)
                        .Field(n => n.NameWithoutSpecialChars, 100.0)
                        .Field(n => n.ProductName)
                        .Field(n => n.TeaserText)
                        .Field(n => n.Description)
                        .Field(n => n.Features)
                        .Field(n => n.Modules)
                       )
                    .Type(TextQueryType.PhrasePrefix)
                   )
                ).Functions(f => f
                    .FieldValueFactor(b => b
                            .Field(p => p.IsBoosted)
                            .Modifier(FieldValueFactorModifier.Log1P))
                )
             )
           )
            .Sort(ss => ss
                .Descending(SortSpecialField.Score))
            .PostFilter(filter => filter.Bool(b => b.Must(must => allFilters)))
            .Source(sr => sr
                .Include(fi => fi
                    .Field(f => f.Name)
                    .Field(n => n.ProductName)
                    .Field(n => n.TeaserText)
                    .Field(f => f.Image)
                    .Field(f => f.Thumbnail)
                    .Field(f => f.Url)
                    .Field(f => f.Features)
                )
            )
       );

Any help is appreciated.任何帮助表示赞赏。

I would preferre not to adapt the product type with the additons to productbundle type..我不希望将带有附加组件的产品类型调整为 productbundle 类型。

I can confirm that.Type() does not mess with the order.我可以确认 .Type() 不会弄乱订单。 My issue was a boosted property not getting a value while indexing the bundles.我的问题是在索引捆绑包时没有获得价值的提升属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM