# Parent Mapping missing

**URL:** https://discuss.elastic.co/t/parent-mapping-missing/5276
**Category:** Elasticsearch
**Created:** [August 30, 2011, 7:32am UTC](https://discuss.elastic.co/t/parent-mapping-missing/5276 "2011-08-30T07:32:42Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Frifri](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@Frifri](https://discuss.elastic.co/u/Frifri)
#### Post date: [August 30, 2011, 7:32am UTC](https://discuss.elastic.co/t/parent-mapping-missing/5276/1 "2011-08-30T07:32:42Z")

</div>

Hello everybody,

I use the following two mappings in a parent child deployment:

curl -X PUT "localhost:9200/parchildev/attachment/\_mapping" -d '{  
"attachment" : {  
"properties" : {  
"file" : {  
"type" : "attachment",  
"fields" : {  
"title" : { "store" : "yes" },  
"file" : { "term\_vector":"with\_positions\_offsets", "store":"yes" }  
}  
}  
}  
}  
}'

curl -X PUT 'localhost:9200/parchildev/comment/\_mapping' -d '{  
"comment" : {  
"\_parent" : {  
"type" : "attachment"  
},  
"properties" : {  
"user" : {"type" : "string"},  
"message" : {"type" : "string", "null\_value" : "na"},  
"car": {"type" : "string"}  
}  
}  
}'

Then I index a pdf into attachment which works fine

Now I put the following to the child mapping:

curl -XPUT 'localhost:9200/parchildev/comment/1?parent='  
-d '{  
"user":"esuser",  
"message":"amplifier",  
"car":"audi a4"  
}'

If I now query, the inner query returns an error message  
curl "${host}/\_search?pretty=true" -d '{  
"fields" : ["title"],  
"query": {  
"bool": {  
"must": [  
{  
"has\_child": {  
"type": "comment",  
"query": {  
"query\_string" : {  
"query" : "amplifier"  
}  
}  
}  
}  
]  
}  
},

"highlight" : {  
"fields" : {  
"file" : {}  
}  
}  
}'

{  
"took" : 5,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 2,  
"successful" : 1,  
"failed" : 1,  
"failures" : [ {  
"index" : "test",  
"shard" : 0,  
"status" : 400,  
"reason" : "SearchParseException[[test][0]: from[-1],size[-1]: Parse  
Failure [Failed to parse source [{\n"fields" : ["title"],\n "query":  
{\n "bool": {\n "must": [\n {\n "has\_child":  
{\n "type": "comment",\n "query":  
{\n"query\_string" : {\n"query" : "amplifier"\n}\n  
}\n }\n }\n ]\n }\n },\n\n"highlight" :  
{\n"fields" : {\n"file" : {}\n}\n}\n}]]]; nested:  
QueryParsingException[[test] [has\_child] Type [comment] does not have  
parent mapping]; "  
} ]  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}

How to define the child mapping? I didn't find any working minimal  
examples...

I used the following two sites  
[http://www.elasticsearch.org/guide/reference/mapping/parent-field.html](http://www.elasticsearch.org/guide/reference/mapping/parent-field.html) and  
[http://www.elasticsearch.org/guide/reference/mapping/](http://www.elasticsearch.org/guide/reference/mapping/)

---

<div class="post-metadata">

### Author: ![Frifri](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@Frifri](https://discuss.elastic.co/u/Frifri)
#### Post date: [September 2, 2011, 11:02am UTC](https://discuss.elastic.co/t/parent-mapping-missing/5276/2 "2011-09-02T11:02:16Z")

</div>

No clue? Looks like there's just a simple error in the declaration of the  
mapping.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [September 5, 2011, 9:00am UTC](https://discuss.elastic.co/t/parent-mapping-missing/5276/3 "2011-09-05T09:00:57Z")

</div>

You seem to search across all indices. See the exception, it comes from the  
"test" index, where it probably does not have the relevant mapping  
definition.

On Fri, Sep 2, 2011 at 2:02 PM, Frifri [henning.frieder@googlemail.com](mailto:henning.frieder@googlemail.com)wrote:

> No clue? Looks like there's just a simple error in the declaration of the  
> mapping.

---

<div class="post-metadata">

### Author: ![Frifri](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@Frifri](https://discuss.elastic.co/u/Frifri)
#### Post date: [September 6, 2011, 8:33am UTC](https://discuss.elastic.co/t/parent-mapping-missing/5276/4 "2011-09-06T08:33:47Z")

</div>

Thx, my bad... embarassing...

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [September 6, 2011, 10:00am UTC](https://discuss.elastic.co/t/parent-mapping-missing/5276/5 "2011-09-06T10:00:11Z")

</div>

Not at all!

On Tue, Sep 6, 2011 at 11:33 AM, Frifri [henning.frieder@googlemail.com](mailto:henning.frieder@googlemail.com)wrote:

> Thx, my bad... embarassing...

---

<div class="post-metadata">

### Author: ![Frifri](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@Frifri](https://discuss.elastic.co/u/Frifri)
#### Post date: [September 10, 2011, 4:00pm UTC](https://discuss.elastic.co/t/parent-mapping-missing/5276/6 "2011-09-10T16:00:05Z")

</div>

Another question on this lovely saturday afternoon:

I use the mappings from the initial post.

Lets say I have 2 parents _A,B_ (type attachment) with only one child \*a \*linked  
to _A_.

- _A_ contains something, but \*not \*"entry 1"
- _a_ contains "entry 1"
- _B_ contains "entry 1"

I need a query structure which returns _A_ (as parent of _a_) and\* B\* for  
the term "entry 1".

I tried like this, but it returns only \*A \*as parent of _a_:

curl "localhost:9200/parchildev/\_search?pretty=true" -d '{  
"fields" : ["title"],  
"query" : {  
"has\_child": {  
"type": "comment",  
"query": {  
"query\_string" : {  
"query" : "entry 1"  
}  
}  
}  
},  
"highlight" : {  
"fields" : {  
"file": {}  
}  
}  
}'

I experimented with a filter, but of course, this one returns _a_ and _B_instead of  
\*A \*and _B_.  
curl "localhost:9200/parchildev/\_search?pretty=true" -d '{  
"fields" : ["title"],  
"filter": {  
"or": [  
{  
"has\_child": {  
"type": "comment",  
"query": {  
"query\_string" : {  
"query" : "entry 1"  
}  
}  
}  
}  
,  
{  
"query": {  
"query\_string" : {  
"query" : "entry 1"  
}  
}  
}  
]  
}  
}'

I think, I need narrow the search pattern of the second search term to the  
attachment mapping. I tried to insert "type": "attachment" like

{  
"query": {  
"type": "attachment",  
"query\_string" : {  
"query" : "entry 1"  
}  
}  
}

but I don't quite well understand the terminology... Sry for this basic  
question.

Thx in advance for your support.

---

<div class="post-metadata">

### Author: ![Frifri](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@Frifri](https://discuss.elastic.co/u/Frifri)
#### Post date: [September 17, 2011, 7:13pm UTC](https://discuss.elastic.co/t/parent-mapping-missing/5276/7 "2011-09-17T19:13:22Z")

</div>

No one has got a clue?

---

<div class="post-metadata">

### Author: ![Frifri](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@Frifri](https://discuss.elastic.co/u/Frifri)
#### Post date: [September 19, 2011, 1:35pm UTC](https://discuss.elastic.co/t/parent-mapping-missing/5276/8 "2011-09-19T13:35:36Z")

</div>

The following query seems to work, but highlighting isn't working at all (so  
i removed it from the gist).

> <https://gist.github.com/anonymous/1226500>

Has someone an idea how to verify if this query does what I want?

---

<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, 3:54am UTC](https://discuss.elastic.co/t/parent-mapping-missing/5276/9 "2017-07-06T03:54:09Z")

</div>


