Skip to content

Instantly share code, notes, and snippets.

@sihutch
Created March 12, 2013 19:53
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 sihutch/5146380 to your computer and use it in GitHub Desktop.
Save sihutch/5146380 to your computer and use it in GitHub Desktop.
curl -XDELETE 'http://localhost:9200/exp/'
#Create the index
curl -XPUT 'http://localhost:9200/exp/'
#Configure the mapping
curl -XPUT localhost:9200/exp/content/_mapping -d '
{
"content": {
"properties": {
"contributors": {
"type": "nested",
"properties": {
"contributorRole": {
"type": "multi_field",
"fields": {
"contributorRole": {
"type": "string",
"index": "analyzed"
},
"untouched": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
},
"identifiers": {
"type": "nested",
"properties": {
"identifierType": {
"type": "multi_field",
"fields": {
"identifierType": {
"type": "string",
"index": "analyzed"
},
"untouched": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
}'
#Index a doc
curl -X PUT "http://localhost:9200/exp/content/1" -d '
{
"title": "Test Title",
"contentType": "Test Content Type",
"publisher": "Publisher",
"contributors": [
{
"contributorRole": "contributor role 1",
"contributorName": "Contributor 1"
},
{
"contributorRole": "contributor role 2",
"contributorName": "Contributor 2"
}
],
"identifiers": [
{
"identifierType": "Test Identifier Type 1",
"identifierValue": "Test Identifier Value1"
},
{
"identifierType": "Test Identifier Type 2",
"identifierValue": "Test Identifier Value2"
}
]
}'
#Search and request facets
curl -X POST "http://localhost:9200/exp/content/_search?pretty=true" -d '
{
"query": {
"query_string": {
"query": "test"
}
},
"facets": {
"contributors.contributorRole.untouched": {
"terms": {
"field": "contributors.contributorRole.untouched"
},
"nested": "contributors"
},
"identifiers.identifierType.untouched": {
"terms": {
"field": "identifiers.identifierType.untouched"
},
"nested": "identifiers"
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment