Skip to content

Instantly share code, notes, and snippets.

@noodlehaus
Created January 15, 2014 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noodlehaus/b0fe69fe83f863bc2ba2 to your computer and use it in GitHub Desktop.
Save noodlehaus/b0fe69fe83f863bc2ba2 to your computer and use it in GitHub Desktop.
example of ES parent-child mapping + query syntax
# topic mappings
POST /index/topic/_mapping -d '{
"topic": {
"properties": {
"section_id": { "type": "integer" },
"title": { "type": "string" },
"message": { "type": "string" },
"post_count": { "type": "integer" },
"status": { "type": "string", "index": "not_analyzed" },
"created_at": { "type": "integer" },
"updated_at": { "type": "integer" }
}
}
}'
# comment mappings
POST /index/comment/_mapping -d '{
"comment": {
"_parent": { "type": "topic" },
"properties": {
"message": { "type": "string" },
"username": { "type": "string", "index": "not_analyzed" },
"status": { "type": "string", "index": "not_analyzed" },
"created_at": { "type": "integer" },
"updated_at": { "type": "integer" }
}
}
}'
<?php
$query = array('bool' => array(
'should' => array(
array(
'has_child' => array(
'type' => 'comment',
'score_type' => 'sum',
'query' => array(
'query_string' => array(
'fields' => array('message^1.2'),
'query' => $query_string
)
)
)
),
array(
'query_string' => array(
'fields' => array('title^2', 'message^1.2'),
'query' => $query_string
)
)
)
));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment