Skip to content

NPE when having two "should" sub-queries with one has_parent w/ inner_hits #50539

Closed
@gbeskales

Description

@gbeskales

Elasticsearch version (bin/elasticsearch --version):
Version: 6.8.2, Build: oss/tar/b506955/2019-07-24T15:24:41.545295Z, JVM: 1.8.0_232

Plugins installed:
"repository-azure", "repository-gcs", "repository-hdfs", "repository-s3"

JVM version (java -version):

openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-8u232-b09-0ubuntu1~18.04.1-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode

OS version (uname -a if on a Unix-like system):
Linux george-P51 4.15.0-72-generic #81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Description of the problem including expected versus actual behavior:
java.lang.NullPointerException is thrown when having a bool query with two should sub-queries and when only one of them have "has_parent" with "inner_hits".

Steps to reproduce:

curl -X PUT "localhost:9200/my_index"

curl -X PUT "localhost:9200/my_index/_mapping/_doc" -H 'Content-Type: application/json' -d'
{
  "properties": {
    "entity_type": {
      "type": "keyword"
    },
    "my_join_field": {
      "type": "join",
      "relations": {
        "question": ["answer"],
        "person": ["phone"]
      }
    }
  }
}
'

curl -X PUT "localhost:9200/my_index/_doc/1?refresh" -H 'Content-Type: application/json' -d'
{
  "text": "This is a question",
  "my_join_field": {
    "name": "question"
  },
  "entity_type": "question"
}
'

curl -X PUT "localhost:9200/my_index/_doc/2?routing=1&refresh" -H 'Content-Type: application/json' -d'
{
  "text": "This is an answer",
  "my_join_field": {
    "name": "answer", 
    "parent": "1" 
  },
  "entity_type": "answer"
}
'

curl -X PUT "localhost:9200/my_index/_doc/3?refresh" -H 'Content-Type: application/json' -d'
{
  "text": "This is a person",
  "my_join_field": {
    "name": "person"
  },
  "entity_type": "person"
}
'

curl -X PUT "localhost:9200/my_index/_doc/4?routing=3&refresh" -H 'Content-Type: application/json' -d'
{
  "text": "This is an phone",
  "my_join_field": {
    "name": "phone", 
    "parent": "3" 
  },
  "entity_type": "phone"
}
'

curl -X GET "localhost:9200/my_index/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "bool": {
      "should": [
        {
          "term": {
            "entity_type": "person"
          }
        },
        {
          "bool": {
            "filter": [
              {
                "term": {
                  "entity_type": "answer"
                }
              },
              {
                "bool": {
                  "should": [
                    {
                      "has_parent": {
                        "query": {
                          "match_all": {}
                        },
                        "parent_type": "question",
                        "inner_hits": {
                          "name": "inner_hit"
                        }
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}
'

Provide logs (if relevant):

[2019-12-31T10:51:12,807][DEBUG][o.e.a.s.TransportSearchAction] [mtFKkTf] [20] Failed to execute fetch phase
org.elasticsearch.transport.RemoteTransportException: [mtFKkTf][127.0.0.1:9300][indices:data/read/search[phase/fetch/id]]
Caused by: java.lang.NullPointerException
	at org.elasticsearch.index.mapper.IdFieldMapper$IdFieldType.termsQuery(IdFieldMapper.java:152) ~[elasticsearch-6.8.2.jar:6.8.2]
	at org.elasticsearch.index.mapper.IdFieldMapper$IdFieldType.termQuery(IdFieldMapper.java:128) ~[elasticsearch-6.8.2.jar:6.8.2]
	at org.elasticsearch.join.query.ParentChildInnerHitContextBuilder$JoinFieldInnerHitSubContext.topDocs(ParentChildInnerHitContextBuilder.java:159) ~[?:?]
	at org.elasticsearch.search.fetch.subphase.InnerHitsFetchSubPhase.hitsExecute(InnerHitsFetchSubPhase.java:53) ~[elasticsearch-6.8.2.jar:6.8.2]
	at org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:175) ~[elasticsearch-6.8.2.jar:6.8.2]
	at org.elasticsearch.search.SearchService.lambda$executeFetchPhase$3(SearchService.java:541) ~[elasticsearch-6.8.2.jar:6.8.2]
	at org.elasticsearch.search.SearchService$3.doRun(SearchService.java:381) [elasticsearch-6.8.2.jar:6.8.2]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.8.2.jar:6.8.2]
	at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:41) [elasticsearch-6.8.2.jar:6.8.2]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:751) [elasticsearch-6.8.2.jar:6.8.2]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.8.2.jar:6.8.2]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_232]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_232]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_232]

Metadata

Metadata

Labels

:Search/SearchSearch-related issues that do not fall into other categories

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions