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



我是Elastic Search的新手,偶然发现了这个问题。当从同一索引中搜索多个文档类型时,这些类型将被附加在结果文档集中,而不是按增强字段进行默认排序。我的文档类型共享相同的字段。

这是我的搜索查询:

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)
)
)
);

感谢您的帮助。

我宁愿不将带有附加组件的产品类型调整为产品捆绑包类型。。

我可以确认.Type((没有扰乱订单。我的问题是一个增强的属性在对捆绑包进行索引时没有得到值。

最新更新