Last active
December 18, 2015 01:39
-
-
Save jbong/5705764 to your computer and use it in GitHub Desktop.
elasticsearch grandparent issue 0.90.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Remove old data | |
curl -XDELETE "http://localhost:9200/grandissue" | |
# Create index with defaults | |
curl -XPOST "http://localhost:9200/grandissue" -d '{ | |
"settings": { | |
"index": { | |
"number_of_shards": 4, | |
"number_of_replicas": 1 | |
} | |
} | |
}' | |
# Add GrandParent mapping | |
curl -XPOST "http://localhost:9200/grandissue/grandparent/_mapping" -d '{ | |
"grandparent":{ | |
"properties":{ | |
"name":{ | |
"type":"string", | |
"index":"analyzed", | |
"analyzer":"default" | |
} | |
} | |
} | |
}' | |
# Add Parent mapping | |
curl -XPOST "http://localhost:9200/grandissue/parent/_mapping" -d '{ | |
"parent":{ | |
"_parent":{ | |
"type":"grandparent" | |
}, | |
"properties":{ | |
"name":{ | |
"type":"string", | |
"index":"analyzed", | |
"analyzer":"default" | |
} | |
} | |
} | |
}' | |
# Add Child mapping | |
curl -XPOST "http://localhost:9200/grandissue/child/_mapping" -d '{ | |
"child":{ | |
"_parent":{ | |
"type":"parent" | |
}, | |
"properties":{ | |
"name":{ | |
"type":"string", | |
"index":"analyzed", | |
"analyzer":"default" | |
} | |
} | |
} | |
}' | |
# Add a grandparent document | |
curl -XPOST "http://localhost:9200/grandissue/grandparent/1" -d '{ | |
"name" : "Bob" | |
}' | |
# Test Search for grandparent - should return document | |
curl -XGET 'http://localhost:9200/grandissue/grandparent/_search?pretty=true' -d '{ | |
"query" : { | |
"match" : { | |
"name" : "bob" | |
} | |
} | |
}' | |
# Add a parent document | |
curl -XPOST "http://localhost:9200/grandissue/parent/2?parent=1&routing=1" -d '{ | |
"name" : "Jim" | |
}' | |
# Test Search for parent (include grandparent id & type in script fields) - should return document | |
curl -XGET 'http://localhost:9200/grandissue/parent/_search?pretty=true' -d '{ | |
"query" : { | |
"match" : { | |
"name" : "jim" | |
} | |
}, | |
"script_fields": { | |
"parent_id_in_script": { | |
"script": "org.elasticsearch.index.mapper.Uid.idFromUid(doc[\"_parent\"].value)" | |
}, | |
"parent_type_in_script": { | |
"script": "org.elasticsearch.index.mapper.Uid.typeFromUid(doc[\"_parent\"].value)" | |
} | |
} | |
}' | |
# Test Search parent that has a grand parent. This will not return any results if the following 2 conditions are TRUE: | |
# 1. elasticsearch version 0.90.1 | |
# 2. child mapping (effectively a grandchild in this example) declared above has been submitted to es. | |
# | |
# If the child mapping declared above has been omitted from the index then this query will work as expected. | |
# | |
# NOTE: ES version 0.90.0 correctly still returns a document. | |
curl -XGET 'http://localhost:9200/grandissue/parent/_search?pretty=true' -d '{ | |
"query" : { | |
"has_parent" : { | |
"parent_type" : "grandparent", | |
"query" : { | |
"match_all" : {} | |
} | |
} | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment