# Wildcard for Nested object

**URL:** <https://discuss.elastic.co/t/wildcard-for-nested-object/103568>\
**Category:** Elasticsearch\
**Created:** [October 11, 2017, 2:32pm UTC](https://discuss.elastic.co/t/wildcard-for-nested-object/103568 "2017-10-11T14:32:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikentyi](https://avatars.discourse-cdn.com/v4/letter/v/41988e/32.png) [@Vikentyi](https://discuss.elastic.co/u/Vikentyi)\
**Post date:** [October 11, 2017, 2:32pm UTC](https://discuss.elastic.co/t/wildcard-for-nested-object/103568/1 "2017-10-11T14:32:04Z")

</div>

Hello.

I have the following mapping (Elasticsearch 5.4.0):

```
{
      "relatedData": {
                        "properties": {
                            "subject": {
                                "type": "nested",
                                "properties": {
                                    "person": {
                                        "properties": {
                                            "firstName": {
                                                "type": "keyword",
                                                "fields": {
                                                    "english": {
                                                        "type": "text",
                                                        "analyzer": "english"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "relation": {
                                        "type": "keyword",
                                        "fields": {
                                            "english": {
                                                "type": "text",
                                                "analyzer": "english"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } 
               }

```

I get the the result for fulltext search using analysed field .english and nested path = it is fine.

But I have problems with wildcard for nested non-analyzed field:

```
   "bool": {
                              "must": [
                                {
                                  "nested": {
                                    "query": {
                                      "wildcard": {
                                        "relatedData.subject.relation": {
                                          "query": "author",
                                          "operator": "OR",
                                          "prefix_length": 0,
                                          "max_expansions": 50,
                                          "fuzzy_transpositions": true,
                                          "lenient": false,
                                          "zero_terms_query": "NONE",
                                          "boost": 1
                                        }
                                      }
                                    },
                                    "path": "relatedData.subject",
                                    "ignore_unmapped": false,
                                    "score_mode": "none",
                                    "boost": 1
                                  }
                                }
                              ],
                              "disable_coord": false,
                              "adjust_pure_negative": true,
                              "boost": 1
                            }
                          }

```

Here I get a response:

```
{
    "error": {
        "root_cause": [
            {
                "type": "parsing_exception",
                "reason": "[wildcard] query does not support [query]",
                "line": 276,
                "col": 53
            }
        ],
        "type": "parsing_exception",
        "reason": "[wildcard] query does not support [query]",
        "line": 276,
        "col": 53
    },
    "status": 400
}

```

Could you explain how to build wildcard query for this example?

P.S. My mapping is more complex but I put here it's simple version.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 11, 2017, 2:50pm UTC](https://discuss.elastic.co/t/wildcard-for-nested-object/103568/2 "2017-10-11T14:50:03Z")

</div>

Where did you find all those parameters on a wildcard query? Can't find any reference in [https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-wildcard-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-wildcard-query.html)

---

<div class="post-metadata">

**Author:** ![Vikentyi](https://avatars.discourse-cdn.com/v4/letter/v/41988e/32.png) [@Vikentyi](https://discuss.elastic.co/u/Vikentyi)\
**Post date:** [October 11, 2017, 3:03pm UTC](https://discuss.elastic.co/t/wildcard-for-nested-object/103568/3 "2017-10-11T15:03:27Z")

</div>

I'have used BoolQueryBuilder in Java. My initial query was for fulltext search (part of query): ("relatedData.subject.relation.english" is analysed field)

```
        "bool": {
                          "must": [
                            {
                              "nested": {
                                "query": {
                                  "match": {
                                    "relatedData.subject.relation.english": {
                                      "query": "author",
                                      "operator": "OR",
                                      "prefix_length": 0,
                                      "max_expansions": 50,
                                      "fuzzy_transpositions": true,
                                      "lenient": false,
                                      "zero_terms_query": "NONE",
                                      "boost": 1
                                    }
                                  }
                                },
                                "path": "relatedData.subject",
                                "ignore_unmapped": false,
                                "score_mode": "none",
                                "boost": 1
                              }
                            }
                          ],
                          "disable_coord": false,
                          "adjust_pure_negative": true,
                          "boost": 1
                        }
                      }

```

And I got the correct result:

```
{
    "took": 15,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": null,
        "hits": [
            {
                "_index": "elastic",
                "_type": "search_type",
                "_id": "7",
                "_score": null,
                "_source": 
                    "relatedData": {
                        "subject": [
                            {
                                "relation": "author",
                                "person": {
                                    "firstName": "aut fn"
                                }
                            }
                        ]
                    }
                },
                "sort": [
                    7
                ]
            }
        ]
    }
}

```

Here I have correct wildcard request but it does not give me correct response: ("relatedData.subject.relation" is non-analysed field)

```
{
                            "bool": {
                              "must": [
                                {
                                  "wildcard": {
                                    "relatedData.subject.relation": {
                                      "wildcard": "*author*",
                                      "boost": 1
                                    }
                                  }
                                }
                              ],
                              "disable_coord": false,
                              "adjust_pure_negative": true,
                              "boost": 1
                            }
                          }

```

On my previous wildcard example I've changed match to wildcard. It is wrong way. But how to make correct? (it is a nested object)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 11, 2017, 3:29pm UTC](https://discuss.elastic.co/t/wildcard-for-nested-object/103568/4 "2017-10-11T15:29:09Z")

</div>

But now I'm confused. This can not give you the error message you wrote earlier.

Whatever running something like `"wildcard": "*author*"` is one of the worst query you can run on an elasticsearch cluster. Basically you are going to run a full scan of the index which is bad.

Look at: [Wildcard query | Elasticsearch Guide [8.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html)

> Note that this query can be slow, as it needs to iterate over many terms. In order to prevent extremely slow wildcard queries, a wildcard term should not start with one of the wildcards \* or ?.

It would help if you provide a full recreation script as described in

> [@About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21):
>
> The heart of the free and open Elastic Stack Elasticsearch is a distributed, RESTful search and analytics engine capable of addressing a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data for lightning fast search, fine‑tuned relevancy, and powerful analytics that scale with ease. warning PLEASE READ THIS SECTION IF IT'S YOUR FIRST POST Some useful links: [elasticsearch reference guide](http://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)[elasticsearch user guide](http://www.elastic.co/guide/en/elasticsearch/guide/current/index.html)[elasticsearch plugins](https://www.elastic.co/guide/en/elasticsearch/plugins/current/index.html)[elasticsearch cl…](https://www.elastic.co/guide/en/elasticsearch/client/index.html)

It will help to better understand what you are doing.  
Please, try to keep the example as simple as possible. I mean try without nested things at first...

---

<div class="post-metadata">

**Author:** ![Vikentyi](https://avatars.discourse-cdn.com/v4/letter/v/41988e/32.png) [@Vikentyi](https://discuss.elastic.co/u/Vikentyi)\
**Post date:** [October 11, 2017, 4:25pm UTC](https://discuss.elastic.co/t/wildcard-for-nested-object/103568/5 "2017-10-11T16:25:08Z")

</div>

Yes, I understand it but it is a customer's request for this query. (((  
All other simple wildcard queries work fine but I also need it for nested.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 11, 2017, 5:30pm UTC](https://discuss.elastic.co/t/wildcard-for-nested-object/103568/6 "2017-10-11T17:30:34Z")

</div>

If it's a one time operation, then that's ok. If you mean to implement that as is, then it's bad IMO.

Better to use ngrams in your analysis chain. It will produce much more token, will use more space on disk but will be more efficient.

---

<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:** [November 8, 2017, 5:30pm UTC](https://discuss.elastic.co/t/wildcard-for-nested-object/103568/7 "2017-11-08T17:30:38Z")

</div>

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