Created
January 2, 2014 10:46
-
-
Save alexbrasetvik/8217541 to your computer and use it in GitHub Desktop.
This file contains 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
_type: character | |
first_name: John | |
last_name: Snow | |
--- | |
_type: character | |
first_name: Eddard | |
last_name: Stark | |
This file contains 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
character: | |
dynamic_templates: | |
- name: | |
match: '*_name' | |
mapping: | |
type: multi_field | |
fields: | |
"{name}": | |
type: string | |
analyzer: simple | |
"{name}.exact": | |
type: string | |
index: not_analyzed | |
This file contains 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
#!/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 | |
} | |
' | |
This file contains 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
# Auto generated by Found's Play-tool at 2014-01-02T11:46:52+01:00 | |
version: 0 | |
title: dynamic_templates | |
description: "" |
This file contains 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
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