0
votes

I'm pretty new to Elastic Search and stumbled upon this issue. 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..

1
Can you explain what "the types are getting appended in the result documents set instead of being default sorted by boosted field." means, perhaps with a small dataset example?Russ Cam
@RussCam Hello Russ, the issue is that the "productbundle" documents are added last to the list of the returned results. So in the array with documents, the return set is like this: <documents> <product></product> <product></product> <product></product> <product></product> <product></product> <product></product> <product></product> <productbundle></productbundle> <productbundle></productbundle> </document>mp1990

1 Answers

0
votes

I can confirm that .Type() does not mess with the order. My issue was a boosted property not getting a value while indexing the bundles.