Wildcard search only returns partial results

Hello, i have the following NEST query and my issue is that the wildcard search is only performed on the last field, "title". It ignores the author and subject fields, even though it should be returning data because there is records in the index that match. Any ideas on how to resolve this? Thank you!

   var sr_books = new SearchDescriptor<books_es>()


                        .Index("books_1").Take(10000)
                       .Query(a => a
                              .Bool(b => b
                                .Should(c => c
                                  .Wildcard(d => d
                                    .Field(e => e.author).Field(f => f.subject).Field(m => m.title).CaseInsensitive(true).Value("A*")
                                  )
                                )
                              )

                        )

Looking at the wildcard query this query only supports a single field, so all your Field() calls are overwriting each other till the last.

You need to create one wildcard query per field and then each each via .Should()...

Thanks so much for the help, appreciate it. After rewriting to the following query, it still returns only records for title. Will I need to reference a different SearchDescriptor for each field?

    var sr_book = new SearchDescriptor<book_es>()


                        .Index("books_1").Take(10000)
                       .Query(a => a
                              .Bool(b => b
                                .Should(c => c
                                  .Wildcard(d => d
                                            .Field(m => m.author).CaseInsensitive(true).Value(searchCriteria)
                                  )
                                )
                              )

                        )
                       .Query(a => a
                              .Bool(b => b
                                .Should(c => c
                                  .Wildcard(d => d
                                    .Field(f => title).CaseInsensitive(true).Value(searchCriteria)
                                  )
                                )
                              )

                        )

in this case you are overwriting the query part of your query. What I mean is, that hte should part of a boolean query can take an array as arguments. I expect the client to create an array of queries when .Should() is called several times (this is how other clients do it), but I am not .NET expert.

So awesome. The NEST with .NET did allow an array of queries, example below in case it helps anyone else. The data is now returning expected results. Thanks so much for the help!

 var searchCriteria = "*Bl*";

  sr_books = new SearchDescriptor<Book_ES>()


                        .Index("books_1").Take(10000)
                       .Query(a => a
                              .Bool(b => b
                                .Should(c => c
                                  .Wildcard(d => d
                                            .Field(m => m.author).CaseInsensitive(true).Value(searchCriteria)
                                  ), bb => bb.Wildcard(rr => rr.Field(vv => vv.title).CaseInsensitive(true).Value(searchCriteria)
                                 )
                              )

                        )


                        );

1 Like