Skip to content

Instantly share code, notes, and snippets.

@alessandrobenedetti
Last active December 23, 2015 23:49
Show Gist options
  • Save alessandrobenedetti/6713103 to your computer and use it in GitHub Desktop.
Save alessandrobenedetti/6713103 to your computer and use it in GitHub Desktop.
Elastic Search [Query Time Join] [has_child] Type [<type>] does not have parent mapping
// index type creation
curl -XPUT 'http://localhost:9200/example/' -d '
index :
    number_of_shards : 3
    number_of_replicas : 2
'
curl -XPUT 'http://localhost:9200/example/document3/_mapping' -d '{"document3" : {"properties":{"label" : {"type" : "string", "store" : "yes", "indexed" : "analysed"},"description" : {"type" : "string", "store" : "yes", "indexed" : "analyzed"}}}}'
curl -XPUT 'http://localhost:9200/example/entity6/_mapping' -d '{"entity6" : {"properties":{"label" : {"type" : "string", "store" : "yes", "index" : "analyzed"},"description" : {"type" : "string", "store" : "yes", "index" : "analyzed"}}}}'
curl -XPUT 'http://localhost:9200/example/entity6/_mapping' -d '{"entity6" : {"_parent" : {"type" : "document3"}}}'
// Check the mappings
curl http://localhost:9200/example/entity6/_mapping
curl http://localhost:9200/example/document3/_mapping
//Indexing -> Java API 1000 document3 and 100 entity6
//document3
String json = "{" +
"\"_id\":\"docId"+i+"\"," +
"\"title\":\"Title"+i+"\"," +
"\"content\":\"A process that compacts the index and merges segments in order to improve query performance.\" +\n" +
" \" New secondary segment(s) are created to contain documents inserted into the collection after it has been optimized. \" +\n" +
" \"A Lucene collection must be optimized periodically to maintain satisfactory query performance. \" +\n" +
" \"Optimization is run on the master server only. An optimized index will give you a performance gain at query time of at least 10%. \" +\n" +
" \"This gain may be more on an index that has become fragmented over a period of time with many updates and no optimizations.\" +\n" +
" \" Optimizations require a much longer time than does the distribution of an optimized collection to all slaves. Vegeta"+i+"\"," +
"}";
// entity6
String json = "{" +
"\"_parent\":\""+parentId+"\"," +
"\"label\":\"label"+i+labelContent.toString()+"\"," +
"\"description\":\"A process that compacts the index and merges segments in order to improve query performance." +
" New secondary segment(s) are created to contain documents inserted into the collection after it has been optimized." +
" A Lucene collection must be optimized periodically to maintain satisfactory query performance." +
" Optimization is run on the master server only. An optimized index will give you a performance gain at query time of at least 10%." +
" This gain may be more on an index that has become fragmented over a period of time with many updates and no optimizations." +
" Optimizations require a much longer time than does the distribution of an optimized collection to all slaves. Vegeta"+i+"\"" +
"}";
//querying
{"query":{"has_child":{"type":"entity6","score_type":"max","query":{"term":{"label":"vegeta"}}}}}
@alessandrobenedetti
Copy link
Author

Exception :

nested: QueryParsingException[[exercise] [has_child] Type [entity6] does not have parent mapping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment