Hi folks,
I've been trying to create a simple parent - child relation between
different search types and finally gave up. I'll be happy if you guys
give me a hand on this;
I have 2 types of search documents, simply "package" and "module" as
in programming. Let's talk on the most famous web framework "Django"
package in Python. First, the mappings:
curl -XGET localhost:9200/pydoc/package/_mapping
{"package":{"_source":{"compress":true},"_id":
{"path":"package_name"},"properties":{"summary":{"store":"yes","boost":
1.2,"type":"string"},"keywords":
{"index_name":"tag","store":"yes","boost":
1.4,"type":"string"},"description":{"boost":
0.8,"type":"string"},"package_name":{"store":"yes","boost":
1.8,"type":"string"},"downloads":
{"store":"yes","type":"integer"},"version":
{"index":"not_analyzed","store":"yes","type":"string"}}}}
curl -XGET localhost:9200/pydoc/module/_mapping
{"module":{"_source":{"compress":true},"_routing":
{"required":true},"properties":{"source_code":
{"path":"full","type":"attachment","fields":{"source_code":
{"type":"string"},"author":{"type":"string"},"title":
{"type":"string"},"keywords":{"type":"string"},"date":
{"format":"dateOptionalTime","type":"date"},"content_type":
{"type":"string"}}},"file_path":
{"store":"yes","type":"string"},"import_name":{"store":"yes","boost":
1.8,"type":"string"}},"_parent":{"type":"package"}}}
As we can see, _parent is mapping to "package" type. Than, let's put
our package:
curl -XPUT localhost:9200/pydoc/package/Django -d '{"description":
null, "package_name": "Django", "downloads": 83193, "summary": "A high-
level Python Web framework that encourages rapid development and
clean, pragmatic design.", "version": "1.3.1", "keywords": []}'
{"ok":true,"_index":"pydoc","_type":"package","_id":"Django","_version":
1}
Now, the problematic process, putting the module that has Django
package as parent:
curl -XPUT localhost:9200/pydoc/module/mytest?parent=Django -d
'{ "import_name" : "django.mytest.etc", "file_path" : "/path/to/
module.py", "source_code" : { "content": "" } }'
{"ok":true,"_index":"pydoc","_type":"module","_id":"mytest","_version":
1}
Right, show me the module document we have just put:
curl -XGET localhost:9200/pydoc/module/mytest
{"_index":"pydoc","_type":"module","_id":"mytest","exists":false}
Exist false? Weird. What if we search?
curl -XGET localhost:9200/pydoc/module/_search?
q=import_name:django.mytest.etc
{"took":2,"timed_out":false,"_shards":{"total":5,"successful":
5,"failed":0},"hits":{"total":1,"max_score":1.75,"hits":
[{"_index":"pydoc","_type":"module","_id":"mytest","_score":1.75,
"_source" : { "import_name" : "django.mytest.etc", "file_path" : "/
path/to/module.py", "source_code" : { "content": "" } }}]}}
No parent, no parent, no parent at all...
The funny thing when I _search in opposite direction with has_child
query:
curl -XGET localhost:9200/pydoc/package/_search -d '{"query" : {
"has_child": { "type": "module", "query": { "term": { "import_name" : "django.mytest.etc" } } } } }'
gives me the expected result:
{"took":1,"timed_out":false,"_shards":{"total":5,"successful":
5,"failed":0},"hits":{"total":1,"max_score":1.0,"hits":
[{"_index":"pydoc","_type":"package","_id":"Django","_score":1.0,
"_source" : {"description": null, "package_name": "Django",
"downloads": 83193, "summary": "A high-level Python Web framework that
encourages rapid development and clean, pragmatic design.", "version":
"1.3.1", "keywords": []}}]}}
I don't understand. How can I get the parent docs from modules?
Cheers.