# Wildcard search only returns partial results

**URL:** <https://discuss.elastic.co/t/wildcard-search-only-returns-partial-results/279069>\
**Category:** Elasticsearch\
**Created:** [July 19, 2021, 1:31pm UTC](https://discuss.elastic.co/t/wildcard-search-only-returns-partial-results/279069 "2021-07-19T13:31:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![muns](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@muns](https://discuss.elastic.co/u/muns)\
**Post date:** [July 19, 2021, 1:31pm UTC](https://discuss.elastic.co/t/wildcard-search-only-returns-partial-results/279069/1 "2021-07-19T13:31:55Z")

</div>

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!

```auto
   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*")
                                  )
                                )
                              )

                        )

```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [July 19, 2021, 1:53pm UTC](https://discuss.elastic.co/t/wildcard-search-only-returns-partial-results/279069/2 "2021-07-19T13:53:14Z")

</div>

Looking at the [wildcard query](https://www.elastic.co/guide/en/elasticsearch/reference/7.13/query-dsl-wildcard-query.html) 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()`...

---

<div class="post-metadata">

**Author:** ![muns](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@muns](https://discuss.elastic.co/u/muns)\
**Post date:** [July 19, 2021, 2:37pm UTC](https://discuss.elastic.co/t/wildcard-search-only-returns-partial-results/279069/3 "2021-07-19T14:37:21Z")

</div>

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?

```auto
    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)
                                  )
                                )
                              )

                        )

```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [July 20, 2021, 8:45am UTC](https://discuss.elastic.co/t/wildcard-search-only-returns-partial-results/279069/4 "2021-07-20T08:45:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![muns](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@muns](https://discuss.elastic.co/u/muns)\
**Post date:** [July 20, 2021, 12:54pm UTC](https://discuss.elastic.co/t/wildcard-search-only-returns-partial-results/279069/5 "2021-07-20T12:54:03Z")

</div>

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!

```auto
 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)
                                 )
                              )

                        )

                        );

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 17, 2021, 12:54pm UTC](https://discuss.elastic.co/t/wildcard-search-only-returns-partial-results/279069/6 "2021-08-17T12:54:20Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
