Skip to content

Instantly share code, notes, and snippets.

@bcotter

bcotter/Mappings Secret

Last active November 16, 2015 09:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bcotter/602499d009575c7a7e15 to your computer and use it in GitHub Desktop.
Save bcotter/602499d009575c7a7e15 to your computer and use it in GitHub Desktop.
Getting Started Webinar - Mappings Code
#__________________________________________________
# Mappings
#__________________________________________________
#__________________________________________________
# All documents have a "mapping" (aka a schema).
# This is either defined up-front, or dynamically
# guessed by Elasticsearch
# Let's look at the mapping ES dynamically generated
GET /library/_mapping
#__________________________________________________
# We can add new fields...
PUT /library/books/_mapping
{
"books": {
"properties": {
"my_new_field": {
"type": "string"
}
}
}
}
GET /library/_mapping
#__________________________________________________
# We can also specify custom settings (analyzers, etc)
PUT /library/books/_mapping
{
"books": {
"properties": {
"english_field": {
"type": "string",
"analyzer": "english"
}
}
}
}
GET /library/_mapping
#__________________________________________________
# But we cannot change an existing field!
PUT /library/books/_mapping
{
"books": {
"properties": {
"english_field": {
"type": "double"
}
}
}
}
#__________________________________________________
# So does updating a mapping update the documents too?
GET library/books/_search
GET library/books/_search
{
"query": {
"match": {
"english_field": "fox"
}
}
}
#__________________________________________________
# It often makes sense to map the fields you know
# to avoid problems, and leave the rest dynamic
POST /logs/transactions/
{
"id": 234571
}
POST /logs/transactions/
{
"id": 1391.223
}
GET /logs/transactions/_search
{
"query": {
"filtered": {
"filter": {
"range": {
"id": {
"gt": 1391,
"lt": 1392
}
}
}
}
}
}
GET /logs/_mapping
GET /logs/_search
#__________________________________________________
# We can also define custom analysis chains, for
# more advanced usage. Not enough time now, but
# see:
# More info: https://www.elastic.co/guide/en/elasticsearch/guide/current/analysis-intro.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment