# Using hasChildQuery causes empty results with java API

**URL:** <https://discuss.elastic.co/t/using-haschildquery-causes-empty-results-with-java-api/56259>\
**Category:** Elasticsearch\
**Created:** [July 25, 2016, 6:21am UTC](https://discuss.elastic.co/t/using-haschildquery-causes-empty-results-with-java-api/56259 "2016-07-25T06:21:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vicmosin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vicmosin/32/7953_2.png) [@vicmosin](https://discuss.elastic.co/u/vicmosin)\
**Post date:** [July 25, 2016, 6:21am UTC](https://discuss.elastic.co/t/using-haschildquery-causes-empty-results-with-java-api/56259/1 "2016-07-25T06:21:13Z")

</div>

I am trying to implement has\_child with ES java client. The mapping looks like that:

```
curl -XPUT 'http://localhost:9200/users/' -d '
{
    "mappings": {
        "user": {
            "properties": {
                "firstName": {
                    "type": "string",
                    "analyzer": "standard"
                }
            }
        },
        "meta": {
            "_parent": {
                "type": "user"
            },
            "properties": {
                "data": {
                    "type": "string",
                    "analyzer": "standard"
                },
                "business": {
                    "type": "string",
                    "index" : "not_analyzed"
                }
            }
        }
    }
}
'

```

I can successfully search via REST API with:

```
curl "http://localhost:9200/users/user/_search" -d '{
    "query": {
        "bool": { 
            "must": [
                {
                    "query_string" : {
                        "fields": ["firstName"],
                        "query": "Cho"
                    }
                },
                {
                    "has_child": {
                        "type": "meta",
                        "query": { 
                            "simple_query_string" : {
                                "query": "int*",
                                "fields": ["data"] 
                              }
                        } 
                    }
                }
            ]
        }
    }
}' 

```

but can't make it work with java client. The code I have:

```
SearchRequestBuilder requestBuilder = client.prepareSearch("users")
     .setTypes("user", "meta")
     .setQuery(
             boolQuery()
                    .must(queryStringQuery(String.format("%s*", queryString)).field("firstName"))
                    .must(hasChildQuery("meta", simpleQueryStringQuery(String.format("%s*", queryString)).field("data")))
     .setFrom(page)
     .setSize(size);
SearchResponse searchResponse = requestBuilder
     .execute()
     .actionGet();

```

Both versions (server and client) are 2.1.0. I repeat - the parent/child relations are fine since I can search via REST API. Any thoughts?

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [July 25, 2016, 7:56am UTC](https://discuss.elastic.co/t/using-haschildquery-causes-empty-results-with-java-api/56259/2 "2016-07-25T07:56:48Z")

</div>

The structure of the query in the Java api looks ok. I wonder what `queryString` variable resolve to when you run that Java code. Also the inner query in the `has_child` query seems different than in the rest example (`int*` instead of `Cho`, assuming that `Cho` is the user's query string)?

---

<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 5, 2017, 10:33pm UTC](https://discuss.elastic.co/t/using-haschildquery-causes-empty-results-with-java-api/56259/3 "2017-07-05T22:33:15Z")

</div>


