Skip to content

Instantly share code, notes, and snippets.

@alexbrasetvik
Created January 2, 2014 10:46
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 alexbrasetvik/8217541 to your computer and use it in GitHub Desktop.
Save alexbrasetvik/8217541 to your computer and use it in GitHub Desktop.
_type: character
first_name: John
last_name: Snow
---
_type: character
first_name: Eddard
last_name: Stark
character:
dynamic_templates:
- name:
match: '*_name'
mapping:
type: multi_field
fields:
"{name}":
type: string
analyzer: simple
"{name}.exact":
type: string
index: not_analyzed
#!/bin/bash
export ELASTICSEARCH_ENDPOINT="http://localhost:9200"
# Create indexes
curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{
"settings": {},
"mappings": {
"character": {
"dynamic_templates": [
{
"name": {
"match": "*_name",
"mapping": {
"type": "multi_field",
"fields": {
"{name}": {
"type": "string",
"analyzer": "simple"
},
"{name}.exact": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
]
}
}
}'
# Index documents
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d '
{"index":{"_index":"play","_type":"character"}}
{"first_name":"John","last_name":"Snow"}
{"index":{"_index":"play","_type":"character"}}
{"first_name":"Eddard","last_name":"Stark"}
'
# Do searches
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"aggregations": {
"last_name": {
"terms": {
"field": "last_name"
}
},
"last_name_exact": {
"terms": {
"field": "last_name.exact"
}
}
},
"size": 0
}
'
# Auto generated by Found's Play-tool at 2014-01-02T11:46:52+01:00
version: 0
title: dynamic_templates
description: ""
aggregations:
last_name:
terms:
field: last_name
last_name_exact:
terms:
field: last_name.exact
size: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment