Skip to content

Instantly share code, notes, and snippets.

@babadofar
Created September 10, 2014 08:35
Show Gist options
  • Save babadofar/191559b2634d3e863579 to your computer and use it in GitHub Desktop.
Save babadofar/191559b2634d3e863579 to your computer and use it in GitHub Desktop.
text: This text will be used if nothing else is specified.
analyzer:
myAnalyzer:
type: custom
tokenizer: whitespace
filter:
- lowercase
- reverse
metaphoneAnalyzer:
# Custom text here, since this makes more sense for this analyzer.
text:
- John Smith
- Jon Schmidth
- Eivind
- Øyvind
- Oivin
type: custom
tokenizer: standard
filter:
- double_metaphone # Defined below
filter:
double_metaphone:
type: phonetic
encoder: doublemetaphone
name: John
---
name: jonne
---
name:: Jona
---
name: jon
# Customize mappings. Note: All indexes get the same types.
person:
properties:
nickname:
type: string
# ^ Place your cursor within the nickname object in the analysis view to see how the
# sample values of that field get tokenized.
# Dynamic templates and multi fields are supported.
dynamic_templates:
- name:
match: "name.*"
mapping:
type: multi_field
fields:
double_metaphone:
type: string
analyzer: double_metaphone
exact:
type: string
index: not_analyzed
#!/bin/bash
export ELASTICSEARCH_ENDPOINT="http://localhost:9200"
# Create indexes
curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{
"settings": {
"analysis": {
"text": "This text will be used if nothing else is specified.",
"analyzer": {
"myAnalyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"reverse"
]
},
"metaphoneAnalyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"double_metaphone"
]
}
},
"filter": {
"double_metaphone": {
"type": "phonetic",
"encoder": "doublemetaphone"
}
}
}
},
"mappings": {
"person": {
"properties": {
"nickname": {
"type": "string"
}
},
"dynamic_templates": [
{
"name": {
"match": "name.*",
"mapping": {
"type": "multi_field",
"fields": {
"double_metaphone": {
"type": "string",
"analyzer": "double_metaphone"
},
"exact": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
]
}
}
}'
# Index documents
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d '
{"index":{"_index":"play","_type":"type"}}
{"name":"John"}
{"index":{"_index":"play","_type":"type"}}
{"name":"jonne"}
{"index":{"_index":"play","_type":"type"}}
{"name:":"Jona"}
{"index":{"_index":"play","_type":"type"}}
{"name":"jon"}
'
# Do searches
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"query": {
"match": {
"name": {
"query": "jon",
"fuzziness": 0
}
}
},
"size": 4,
"explain": true
}
'
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"query": {
"match": {
"name": {
"query": "jon",
"fuzziness": 1
}
}
},
"size": 4,
"explain": true
}
'
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"query": {
"match": {
"name": {
"query": "jon",
"fuzziness": 2
}
}
},
"size": 2,
"explain": true
}
'
# Auto generated by Found's Play-tool at 2014-09-10T10:35:38+02:00
version: 0
title: fuzzytest
description: ""
# Sample searches. Press Ctrl-Enter to run.
# Press Shift-Enter to go to focused mode for the selected editor.
# Click "Help" for more shortcuts.
query:
match:
name:
query: jon
fuzziness: 0
# You can specify other search options as well.
size: 4
explain: true
---
query:
match:
name:
query: jon
fuzziness: 1
# You can specify other search options as well.
size: 4
explain: true
---
query:
match:
name:
query: jon
fuzziness: 2
# You can specify other search options as well.
size: 2
explain: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment