Created
January 15, 2014 02:58
-
-
Save noodlehaus/b0fe69fe83f863bc2ba2 to your computer and use it in GitHub Desktop.
example of ES parent-child mapping + query syntax
This file contains hidden or 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
# 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" } | |
} | |
} | |
}' |
This file contains hidden or 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
<?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