Deleting a child mapping affects querying other children of the same parent

Hi all,

recently I came across the problem, described in this post:
Delete one child type mapping, affected other children queries

Unfortunately, there were no replies or comments there. That is why I'll describe the problem once more.
I used the examples provided in the article:
Fun With Elasticsearch's Children and Nested Documents

I've created an "authors" index and added 2 documents to the "bare_author" type, with the help of:

curl -XPUT localhost:9200/authors/bare_author/1 -d'{"name": "Multi G. Enre"}'
curl -XPUT localhost:9200/authors/bare_author/2 -d'{"name": "Alastair Reynolds"}'

Then specified the parent-child relation:

curl -XPOST localhost:9200/authors/book/_mapping -d $'{\n  "book":{\n    "_parent": {"type": "bare_author"}\n  }\n}'

Added 3 documents to the "book" mapping:

curl -XPOST localhost:9200/authors/book/1?parent=2 -d $'{\n   "name": "Revelation Space",\n   "genre": "scifi",\n   "publisher": "penguin"\n}'
curl -XPOST localhost:9200/authors/book/2?parent=1 -d $'{\n   "name": "Guns and lasers",\n   "genre": "scifi",\n   "publisher": "orbit"\n}'
curl -XPOST localhost:9200/authors/book/3?parent=1 -d $'{\n   "name": "Dead in the night",\n   "genre": "thriller",\n   "publisher": "penguin"\n}'

Specified another parent-child relation:

curl -XPOST localhost:9200/authors/magazine/_mapping -d $'{\n  "magazine":{\n    "_parent": {"type": "bare_author"}\n  }\n}'

Added 2 documents to the second type:

curl -XPOST localhost:9200/authors/magazine/1?parent=1 -d $'{\n   "name": "Fun with Elasticsearch",\n   "genre": "blogging",\n   "article": "Parent and Child"\n}'
curl -XPOST localhost:9200/authors/magazine/2?parent=2 -d $'{\n   "name": "You Know, for Search",\n   "genre": "analytic",\n   "article": "Managing Relations"\n}'

Up to this moment all goes well. I'm able to query both children types.
Used this query (via elasticsearch _plugin/head):
http://localhost:9200/authors/book/
_search

{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "bool": {
          "must": {
            "has_parent": {
              "query": {
                "ids": {
                  "type": "bare_author",
                  "values": [
                    "2"
                  ]
                }
              },
              "parent_type": "bare_author"
            }
          }
        }
      }
    }
  },
  "explain": false,
  "fields": [
    "_parent",
    "_source"
  ]
}

to find a book of the author with id=2.

If I now delete the "magazine" type:

curl -XDELETE localhost:9200/authors/magazine

I'm not able to make any other child queries. Even the one given above, results in: 3 shards return no matches, 2 shards return:

"status": 500,
"reason": "QueryPhaseExecutionException[[authors][2]: query[filtered(ConstantScore(BooleanFilter(+CustomQueryWrappingFilter(parent_filter[bare_author](filtered(ConstantScore(_uid:bare_author#2))->cache(_type:bare_author))))))->cache(_type:book)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: RuntimeException[java.lang.NullPointerException]; nested: NullPointerException; "

Like the author of the previous discussion mentioned, restarting the Elasticsearch helps.

Would appreciate any help, ideas, experience.
Thanks in advance!

What version are you on?

Hi, Warkolm! Thanks for your reply!

Sorry, I forgot to clarify that part.
Elasticsearch 1.7.2.
Here is more detailed info from _plugin/head:
"version" : {
"number" : "1.7.2",
"build_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec",
"build_timestamp" : "2015-09-14T09:49:53Z",
"build_snapshot" : false,
"lucene_version" : "4.10.4"
}

Runs on Ubuntu, if this somehow matters.

Thought that this may make something clear for people, with more experience than me :smile:
Here is what could be found in log files:

[2015-09-21 13:09:17,382][INFO ][cluster.metadata         ] [Airstrike] [[authors]] remove_mapping [[magazine]]
[2015-09-21 13:10:04,671][DEBUG][action.search.type       ] [Airstrike] [authors][2], node[FupU8MLoTYuFz-ieKa1Qhg], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@68991775] lastShard [true]
org.elasticsearch.search.query.QueryPhaseExecutionException: [authors][2]: query[filtered(ConstantScore(BooleanFilter(+CustomQueryWrappingFilter(parent_filter[bare_author](filtered(ConstantScore(_uid:bare_author#2))->cache(_type:bare_author))))))->cache(_type:book)],from[0],size[10]: Query Failed [Failed to execute main query]
	at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:163)
	at org.elasticsearch.search.SearchService.loadOrExecuteQueryPhase(SearchService.java:301)
	at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:312)
	at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:231)
	at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:228)
	at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
	at org.elasticsearch.search.internal.ContextIndexSearcher.createNormalizedWeight(ContextIndexSearcher.java:136)
	at org.elasticsearch.index.search.child.CustomQueryWrappingFilter.getDocIdSet(CustomQueryWrappingFilter.java:72)
	at org.elasticsearch.common.lucene.search.XBooleanFilter.getDocIdSet(XBooleanFilter.java:59)
	at org.elasticsearch.common.lucene.search.ApplyAcceptedDocsFilter.getDocIdSet(ApplyAcceptedDocsFilter.java:46)
	at org.apache.lucene.search.ConstantScoreQuery$ConstantWeight.scorer(ConstantScoreQuery.java:157)
	at org.apache.lucene.search.FilteredQuery$RandomAccessFilterStrategy.filteredScorer(FilteredQuery.java:542)
	at org.apache.lucene.search.FilteredQuery$FilterStrategy.filteredBulkScorer(FilteredQuery.java:504)
	at org.apache.lucene.search.FilteredQuery$1.bulkScorer(FilteredQuery.java:150)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:618)
	at org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:191)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:491)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:448)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:281)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:269)
	at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:157)
	... 8 more
Caused by: java.lang.NullPointerException
	at org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData$GlobalAtomicFieldData.getOrdinalsValues(ParentChildIndexFieldData.java:353)
	at org.elasticsearch.index.search.child.ParentConstantScoreQuery.createWeight(ParentConstantScoreQuery.java:97)
	at org.apache.lucene.search.IndexSearcher.createNormalizedWeight(IndexSearcher.java:684)
	at org.elasticsearch.search.internal.ContextIndexSearcher.createNormalizedWeight(ContextIndexSearcher.java:133)
	... 22 more
[2015-09-21 13:10:04,671][DEBUG][action.search.type       ] [Airstrike] [authors][3], node[FupU8MLoTYuFz-ieKa1Qhg], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@68991775]
org.elasticsearch.search.query.QueryPhaseExecutionException: [authors][3]: query[filtered(ConstantScore(BooleanFilter(+CustomQueryWrappingFilter(parent_filter[bare_author](filtered(ConstantScore(_uid:bare_author#2))->cache(_type:bare_author))))))->cache(_type:book)],from[0],size[10]: Query Failed [Failed to execute main query]
	at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:163)
	at org.elasticsearch.search.SearchService.loadOrExecuteQueryPhase(SearchService.java:301)
	at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:312)
	at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:231)
	at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:228)
	at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)

This is a bug. It has been fixed in 2.0.0-beta2. The fix can be backported to 1.7, but not sure if there will be a 1.7 release soon.

1 Like

Hi mvg, thank you very much for clarifying that!
And special thanks for the quick reply! :smile:
Is there any information available about the release date of 2.0.0 as a stable release?

There is no hard date for when a stable release goes out. First a RC release goes out and if all goes well then the GA release goes out. I expect a RC release relatively soon.

If I'm reading correctly, this is a bug that was fixed in 2.x. But not really, since parent-child was redesigned in 2.0 and does not work like in the example shown here: in 2.x parents and child must be created in the same call, so it's actually a new form of nested ... you just removed parent-child feature entirely:

https://www.elastic.co/guide/en/elasticsearch/reference/2.0/breaking_20_parent_child_changes.html#_parent_type_cannot_pre_exist

Is there any plan to backport the fix to this bug to 1.7? Since our application relies on the real parent-child relationship (parents are created ahead of time, child is created referencing the parent, a relationship instead of nesting documents) we can't move to 2.x until we refactor everything.

Thanks.