Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gbeskales opened this issue Dec 31, 2019 · 3 comments · Fixed by #50709
Closed

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

gbeskales opened this issue Dec 31, 2019 · 3 comments · Fixed by #50709
Assignees
Labels
:Search/Search Search-related issues that do not fall into other categories

Comments

@gbeskales
Copy link

gbeskales commented Dec 31, 2019

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]
@cbuescher cbuescher added the :Search/Search Search-related issues that do not fall into other categories label Jan 2, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Search)

@mayya-sharipova
Copy link
Contributor

mayya-sharipova commented Jan 6, 2020

I confirm the error on 7.x. The error happens in this case because inner hits get applied to all top hits, while they are relevant only to the second hit.

@mayya-sharipova mayya-sharipova self-assigned this Jan 7, 2020
mayya-sharipova added a commit to mayya-sharipova/elasticsearch that referenced this issue Jan 7, 2020
When there several subqueries on different relations of the join field,
and only one of subqueries is using inner_hits, NPE occurs.
This PR prevents NPE error.

Closes elastic#50539
mayya-sharipova added a commit that referenced this issue Jan 7, 2020
When there several subqueries on different relations of the join field,
and only one of subqueries is using inner_hits, NPE occurs.
This PR prevents NPE error.

Closes #50539
mayya-sharipova added a commit that referenced this issue Jan 7, 2020
When there several subqueries on different relations of the join field,
and only one of subqueries is using inner_hits, NPE occurs.
This PR prevents NPE error.

Closes #50539
mayya-sharipova added a commit that referenced this issue Jan 7, 2020
When there several subqueries on different relations of the join field,
and only one of subqueries is using inner_hits, NPE occurs.
This PR prevents NPE error.

Closes #50539
@mayya-sharipova
Copy link
Contributor

@gbeskales thank you for filling the issue. The bug was fixed, and the patch will be available in the next releases of elasticsearch.

SivagurunathanV pushed a commit to SivagurunathanV/elasticsearch that referenced this issue Jan 23, 2020
When there several subqueries on different relations of the join field,
and only one of subqueries is using inner_hits, NPE occurs.
This PR prevents NPE error.

Closes elastic#50539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Search/Search Search-related issues that do not fall into other categories
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants