elasticsearch/elasticsearch — Issue #1510: Weird behaviour and unexpected exceptions with nested queries
Author: 314fc
Created: 2011-11-29 15:56:23+00:00
State: open

I've met with some exceptions trying to execute some nested queries. It's an erratic bug, because sometimes it works fine and other it fails. I've tried it in a fresh ElasticSearch version 0.18.5.

The following commands will reproduce the exceptions sometimes. Most of the times the last two queries (nested query and mixed query) work fine, but suddenly they will fail.

# First we delete indices
curl -XDELETE 'http://localhost:9200/users/'
curl -XDELETE 'http://localhost:9200/entities/'

# First index creation (users)
curl -XPUT 'http://localhost:9200/users/' -d '
index :
number_of_shards : 10
number_of_replicas : 0
'

# Insert document in first index (users)
curl -XPUT http://localhost:9200/users/user/1 -d '{
"name": "John",
"surname": "Doe"
}'

# Second index creation (entities)
curl -XPUT 'http://localhost:9200/entities/' -d '
index :
number_of_shards : 10
number_of_replicas : 0
'

# Create Nested Mapping in "entities" index called "nestedtest"
curl -XPUT 'http://localhost:9200/entities/nestedtest/_mapping' -d '
{
"tweet" : {
"properties" : {
"name" : {"type" : "string", "store" : "yes"},
"tweets": {"type": "nested"}
}
}
}
'

# Created Not-Nested Mapping in "entities" index called "notnestedtest"
curl -XPUT 'http://localhost:9200/entities/notnestedtest/_mapping' -d '
{
"tweet" : {
"properties" : {
"name" : {"type" : "string", "store" : "yes"},
"text" : {"type" : "string", "store" : "yes"}
}
}
}
'

# Insert document of type nestedtest
curl -XPUT http://localhost:9200/entities/nestedtest/1 -d '{
"name": "document1",
"tweets": [{"message": "this is a test message", "author":"author1"},
{"message": "second message", "author":"author2"}]
}'

# Insert document of type notnestedtest
curl -XPUT http://localhost:9200/entities/notnestedtest/2 -d '{
"name": "document2",
"text": "Text of document2"
}'

# Nested query
curl -XGET http://localhost:9200/entities/nestedtest/_search?pretty=true -d '{
"query" : {
"nested" : {
"path" : "tweets",
"score_mode" : "avg",
"query" : {
"bool" : {
"must" : [
{
"text" : {"tweets.message" : "message"}
},
{
"text" : {"author" : "author2"}
}
]
}
}
}
}
}'

# Mixed nested - not nested query
curl -XGET http://localhost:9200/entities/_search?pretty=true -d '{
"query" : {
"bool" : {
"should" : [
{
"text" : {"name" : "document2"}
},
{
"nested" : {
"path" : "tweets",
"score_mode" : "avg",
"query" : {
"bool" : {
"must" : [
{
"text" : {"tweets.message" : "second"}
},
{
"text" : {"tweets.message" : "message"}
},
{
"text" : {"author" : "author2"}
}
]
}
}
}
}
]
}
}
}'