# Wildcard search on nested object in ElasticSearch

**URL:** <https://discuss.elastic.co/t/wildcard-search-on-nested-object-in-elasticsearch/19895>\
**Category:** Elasticsearch\
**Created:** [September 21, 2014, 9:13am UTC](https://discuss.elastic.co/t/wildcard-search-on-nested-object-in-elasticsearch/19895 "2014-09-21T09:13:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abraham\_polishchuk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abraham_polishchuk/32/1272_2.png) [@abraham\_polishchuk](https://discuss.elastic.co/u/abraham_polishchuk)\
**Post date:** [September 21, 2014, 9:13am UTC](https://discuss.elastic.co/t/wildcard-search-on-nested-object-in-elasticsearch/19895/1 "2014-09-21T09:13:02Z")

</div>

Let's say we are storing objects of type vehicle which have a reference to  
a type owner in the following structure. Then Running the following request:

`POST: localhost:9200/15/vehicles/\_search'

with the following body:

```
 { "query": { "wildcard": {"make":"*toy*"} }}

```

returns the relevant objects:

```
     "took": 5,
     "timed_out": false,
     "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
     },
    "hits": {
        "total": 1,
    "max_score": 1,
    "hits": [
        {
            "_index": "15.index",
            "_type": "vehicle",
            "_id": "352",
            "_score": 1,
            "_source": {
                "id": "352",
                "name": "toyota",
                "owner_id": "12",
                "owner": {
                    "id": "12",
                    "name": "John Smith",
                    "login_id": 1,
                    "active": true,
                }
            }
        }
    ]
}

```

I am now attempting to query by nested object (e.g. all vehicles that  
belong to user John Smith)

```
 {"query": {"wildcard": {"owner.name": "*John*"}}}

```

returns no results, while:

```
 {"query": {"wildcard": {"owner": {"name": "*John*"}}}}

```

errors out with:

```
  "error": "SearchPhaseExecutionException[Failed to execute phase 

```

[query], all shards failed; shardFailures {....  
[4]: SearchParseException[....  
Parse Failure [Failed to parse source [{ "query": { "wildcard":  
{"owner": {"name":"_ab_"} }}}]]]; nested: QueryParsingException[....  
[wildcard] query does not support [name]]; }{....  
[3]: SearchParseException[....  
: Parse Failure [Failed to parse source [{ "query": { "wildcard":  
{"owner": {"name":"_ab_"} }}}]]]; nested: QueryParsingException[....  
[wildcard] query does not support [name]]; }{....  
[2]: SearchParseException[....  
]: Parse Failure [Failed to parse source [{ "query": { "wildcard":  
{"owner": {"name":"_ab_"} }}}]]]; nested: QueryParsingException[....  
[wildcard] query does not support [name]]; }{....  
: SearchParseException[[....  
: Parse Failure [Failed to parse source [{ "query": { "wildcard":  
{"owner": {"name":"_ab_"} }}}]]]; nested: QueryParsingException[....  
[wildcard] query does not support [name]]; }{....  
[0]: SearchParseException[....: Parse Failure [Failed to parse source  
[{ "query": { "wildcard": {"owner": {"name":"_ab_"} }}}]]];  
nested: QueryParsingException[.... [wildcard] query does not support  
[name]]; }]",  
"status": 400

What is the correct format for a query (wildcard or otherwise) against a  
nested object? How specifically do wildcard queries differ from that  
template (if at all)?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/55a91fbc-5bc4-44b6-a39e-1efc942fe63d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/55a91fbc-5bc4-44b6-a39e-1efc942fe63d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [September 21, 2014, 9:49am UTC](https://discuss.elastic.co/t/wildcard-search-on-nested-object-in-elasticsearch/19895/2 "2014-09-21T09:49:23Z")

</div>

Try this:  
{"query": {"wildcard": {"owner.name": « _john_"}}}

Wildcard is not analyzed

Also, don’t use wildcard queries.  
Look : [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html#query-dsl-wildcard-query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html#query-dsl-wildcard-query)

Note 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 ?.

--  
David Pilato | Technical Advocate | [elasticsearch.com](http://elasticsearch.com)  
[david.pilato@elasticsearch.com](mailto:david.pilato@elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 21 septembre 2014 à 11:13:10, abraham polishchuk ([apolishc@gmail.com](mailto:apolishc@gmail.com)) a écrit:

Let's say we are storing objects of type vehicle which have a reference to a type owner in the following structure. Then Running the following request:

`POST: localhost:9200/15/vehicles/\_search'

with the following body:

```
 { "query": { "wildcard": {"make":"*toy*"} }}

```

returns the relevant objects:

```
     "took": 5,
     "timed_out": false,
     "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
     },
    "hits": {
        "total": 1,
    "max_score": 1,
    "hits": [
        {
            "_index": "15.index",
            "_type": "vehicle",
            "_id": "352",
            "_score": 1,
            "_source": {
                "id": "352",
                "name": "toyota",
                "owner_id": "12",
                "owner": {
                    "id": "12",
                    "name": "John Smith",
                    "login_id": 1,
                    "active": true,
                }
            }
        }
    ]
}

```

I am now attempting to query by nested object (e.g. all vehicles that belong to user John Smith)

```
 {"query": {"wildcard": {"owner.name": "*John*"}}}

```

returns no results, while:

```
 {"query": {"wildcard": {"owner": {"name": "*John*"}}}}

```

errors out with:

```
  "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {....
  [4]: SearchParseException[....
  Parse Failure [Failed to parse source [{ \"query\": { \"wildcard\": {\"owner\": {\"name\":\"*ab*\"} }}}]]]; nested: QueryParsingException[....
 [wildcard] query does not support [name]]; }{....
 [3]: SearchParseException[....
: Parse Failure [Failed to parse source [{ \"query\": { \"wildcard\": {\"owner\": {\"name\":\"*ab*\"} }}}]]]; nested: QueryParsingException[....
 [wildcard] query does not support [name]]; }{....
 [2]: SearchParseException[....
 ]: Parse Failure [Failed to parse source [{ \"query\": { \"wildcard\": {\"owner\": {\"name\":\"*ab*\"} }}}]]]; nested: QueryParsingException[....
 [wildcard] query does not support [name]]; }{....
 : SearchParseException[[....
: Parse Failure [Failed to parse source [{ \"query\": { \"wildcard\": {\"owner\": {\"name\":\"*ab*\"} }}}]]]; nested: QueryParsingException[....
 [wildcard] query does not support [name]]; }{....
 [0]: SearchParseException[....: Parse Failure [Failed to parse source [{ \"query\": { \"wildcard\": {\"owner\": {\"name\":\"*ab*\"} }}}]]]; nested: QueryParsingException[.... [wildcard] query does not support [name]]; }]",
"status": 400

```

## What is the correct format for a query (wildcard or otherwise) against a nested object? How specifically do wildcard queries differ from that template (if at all)?

You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/55a91fbc-5bc4-44b6-a39e-1efc942fe63d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/55a91fbc-5bc4-44b6-a39e-1efc942fe63d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.541e9f23.6b8b4567.2bf8%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.541e9f23.6b8b4567.2bf8%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 1:00am UTC](https://discuss.elastic.co/t/wildcard-search-on-nested-object-in-elasticsearch/19895/3 "2017-07-06T01:00:56Z")

</div>


