Last active
December 10, 2015 13:19
-
-
Save webmusing/4440320 to your computer and use it in GitHub Desktop.
Unable to search for parent and child documents using Elasticsearch
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
I have a child document such as this: | |
{ | |
_index: prototype_2013.01.03 | |
_type: chow-clfg | |
_id: PybhISPURJS5q5DbQMEnTA | |
_score: 6.8785243 | |
_source: { | |
chow-clfg: { | |
@type: chow-clfg | |
clfg: Cg5iU1BHZ88kAAAAYAE | |
@timestamp: 2013-01-03T02:26:00.000Z | |
count: 1 | |
} | |
} | |
} | |
and I have parent documents such as this: | |
{ | |
_index: prototype_2013.01.03 | |
_type: chow-demo | |
_id: _IZFN7tQSWiD9lwFrrKCTw | |
_score: 10.197559 | |
_source: { | |
timestamp: [03/Jan/2013:02:15:29 +0000] | |
httpcode: [200] | |
clfg: [Cg5iU1BHZ88kAAAAYAE] | |
user_agent: ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.26.17 (KHTML, like Gecko) Version/6.0.2 Safari/536.26.17 -"] | |
@timestamp: 2013-01-03T02:15:29.000Z | |
@type: chow-demo | |
} | |
} | |
However when I use the following curl command: | |
curl -XPOST "localhost:9200/prototype_2013.01.03/chow-demo/_search" -d | |
'{ | |
"query": { | |
"has_child": { | |
"type": "chow-clfg", | |
"query": { | |
"term": { | |
"clfg": "Cg5iU1BHZ88kAAAAYAE" | |
} | |
} | |
} | |
} | |
}' | |
I get absolutely no results. | |
My mappings are as follows for child documents: | |
"chow-clfg" : { | |
"dynamic" : "true", | |
"_source" : { | |
"enabled" : true | |
}, | |
"_ttl" : { | |
"enabled" : true, | |
"default" : "30m" | |
}, | |
"properties" : { | |
"@timestamp" : { | |
"format" : "dateOptionalTime", | |
"type" : "date" | |
}, | |
"clfg" : { | |
"analyzer" : "keyword", | |
"type" : "string" | |
}, | |
"count" : { | |
"type" : "long" | |
}, | |
"@type" : { | |
"analyzer" : "keyword", | |
"type" : "string" | |
} | |
}, | |
"_parent" : { | |
"type" : "chow-demo" | |
} | |
While parent documents are as follows: | |
"chow-demo" : { | |
"properties" : { | |
"@fields" : { | |
"dynamic" : "true", | |
"properties" : { | |
"clfg" : { | |
"analyzer" : "keyword", | |
"type" : "string" | |
}, | |
"httpcode" : { | |
"type" : "long" | |
}, | |
"timestamp" : { | |
"type" : "string" | |
}, | |
"user_agent" : { | |
"analyzer" : "keyword", | |
"type" : "string" | |
}, | |
} | |
}, | |
"@timestamp" : { | |
"format" : "dateOptionalTime", | |
"type" : "date" | |
}, | |
"@type" : { | |
"analyzer" : "keyword", | |
"type" : "string" | |
} | |
} | |
} | |
I am not sure why there should be no results at this point. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment