elasticsearch


Elasticsearch - Has_Parent or Has_Child query returning empty results


I'm using Elasticsearch RC 2.0.0.
I got some parent-child relations In my Elasticsearch db. I want to retrieve all Children related to a parent object. I always receive an empty list of results. I followed the instructions of the elasticsearch documentation and I compared my code to several Books. I don't understand, why my query should return an empty result.
In this case I built an simplified example. I put two objects to elasticsearch and set object a as the parent of object b. Then I try to retrieve all objects, wich have a parent of type a.
This is my Input:
PUT test
PUT test/myobject/_mapping
{
"myobject":{
"_parent" : {"type":"pobject"},
"properties" : {
"name" : {"type":"string"}
}
}
}
PUT test/pobject/_mapping
{
"pobject" : {
"properties": {
"name": {"type":"string"}
}
}
}
PUT test/pobject/1
{
"name":"theParent"
}
PUT test/myobject/1?_parent=1&routing=_id
{
"name":"theChild"
}
POST test/myobject/_search?routing=_id
{
"query":{
"has_parent":{
"type":"pobject",
"query":{
"match_all":{}
}
}
}
}
This will return
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
The mistake is here: PUT test/myobject/1?_parent=1&routing=_id
The parameter is parent, not _parent.
POST test/myobject/1?parent=1
{
"name": "theChild"
}
Also, you don't need to use routing=_id. See the documentation.
The complete list of commands to test:
DELETE test
PUT test
PUT test/myobject/_mapping
{
"myobject": {
"_parent": {
"type": "pobject"
},
"properties": {
"name": {
"type": "string"
}
}
}
}
PUT test/pobject/_mapping
{
"pobject": {
"properties": {
"name": {
"type": "string"
}
}
}
}
POST test/pobject/1
{
"name": "theParent"
}
POST test/myobject/1?parent=1
{
"name": "theChild"
}
POST test/myobject/_search
{
"query": {
"has_parent": {
"parent_type": "pobject",
"query": {
"match_all": {}
}
}
}
}

Related Links

How do i add boosting to the elasticsearch mapping in ONGR?
Is it possible to use doc_count as a term in elasticsearch?
Elastic search aggregation with sort
Elasticsearhc- how to do multi search request on Sense or Head plugin
How do I configure/initialize a custom Elasticsearch Tokenizer
Combining log entries with logstash
How to import CSV data using Logstash for field type completion in Elasticsearch suggester
How can I interpret the result of percentiles aggregation type
elastic search select fields to return in aggregation
How to Focus Search On One Part of a Document
How to calculate cooccurrences on a set of texts with Elasticsearch
elasticsearch edge_ngrams analyzer is not found
Double wildcard in query causes weird highlighting for plain/fast vectors elasticsearch highlighters
Get Elasticsearch response in DataTable in C#.Net
Elasticsearch NoNodeAvailableException issue
Why Elasticsearch snapshot stats number_of_files differs from actual indices count?

Categories

HOME
firebase
yaml
windows-8.1
focus
stacktrace.js
openlayers-3
mongoid
biztalk-2010
tfs2015
share
repair
firebase-dynamic-links
phpseclib
solution
csrf
cname
responsivevoice
rpmbuild
cpu-usage
bazaar
bluemix-mobile-services
perfino
crud
tf-idf
ibm-connections
credit-card
dotcms
vcenter
progid
char-pointer
orchardcms-1.8
spinner
cordys-opentext
cargo
aurelia-http-client
gitolite
selenide
stat
oauth2-playground
hypothesis-test
raytracing
httphandler
transparency
moinmoin
tinyioc
rm
iptv
mpmovieplayercontroller
email-injection
qtextedit
yargs
cocoa-bindings
scheduledexecutorservice
system.web.optimization
seccomp
uibinder
apple-configurator
vim-plugin
json-spirit
phpquery
openshift-cartridge
explain
python-curses
mxe
wicket-1.5
global-scope
webmethod
lumia-imaging-sdk
distributed-r
commenting
webaii
django-settings
ctp
disjoint-union
bcdedit
ntlmv2
wndproc
hardcode
fitch-proofs
mvcrecaptcha
vows
uipasteboard
cewolf
ognl
pinax
asdoc
processors

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile