Created
July 30, 2013 18:12
-
-
Save anonymous/6115360 to your computer and use it in GitHub Desktop.
Demo how stop words and length token filter work for elasticsearch
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
# Remove old data | |
curl -XDELETE "http://localhost:9200/stoptest" | |
# Create index with settings | |
curl -XPOST "http://localhost:9200/stoptest/" -d ' | |
{ | |
"settings":{ | |
"index":{ | |
"analysis":{ | |
"analyzer":{ | |
"test":{ | |
"type":"custom", | |
"tokenizer":"standard", | |
"filter":[ | |
"lowercase", | |
"stop" | |
] | |
}, | |
"test_length_filter":{ | |
"type":"custom", | |
"tokenizer":"standard", | |
"filter":[ | |
"lowercase", | |
"custom_length" | |
] | |
} | |
}, | |
"filter":{ | |
"custom_length":{ | |
"type":"length", | |
"min":3, | |
"max":2000 | |
} | |
} | |
} | |
} | |
} | |
} | |
' | |
# Define mapping | |
curl -XPOST "http://localhost:9200/stoptest/stoptest/_mapping" -d ' | |
{ | |
"stoptest":{ | |
"properties":{ | |
"test":{ | |
"type":"string", | |
"analyzer":"test" | |
}, | |
"test_length":{ | |
"type":"string", | |
"analyzer":"test_length_filter" | |
} | |
} | |
} | |
} | |
' | |
# Create Document | |
curl -XPOST "http://localhost:9200/stoptest/stoptest/" -d ' | |
{ | |
"test":"the lazy brown fox will not give a reproduction to me", | |
"test_length":"the lazy brown fox will not give a reproduction to me" | |
} | |
' | |
# Wait for ES to be synced (aka refresh indices) | |
curl -XPOST "http://localhost:9200/stoptest/_refresh" | |
# Search on stop word - NO RESULTS | |
curl -XPOST "http://localhost:9200/stoptest/_search?pretty=true" -d ' | |
{ | |
"query":{ | |
"term":{ | |
"test":"to" | |
} | |
} | |
} | |
' | |
# This query works since me isn't a stop word | |
curl -XPOST "http://localhost:9200/stoptest/_search?pretty=true" -d ' | |
{ | |
"query":{ | |
"term":{ | |
"test":"me" | |
} | |
} | |
} | |
' | |
# Search on token too small - NO RESULTS | |
curl -XPOST "http://localhost:9200/stoptest/_search?pretty=true" -d ' | |
{ | |
"query":{ | |
"term":{ | |
"test_length":"me" | |
} | |
} | |
} | |
' | |
# Search on term long enough - gets results | |
curl -XPOST "http://localhost:9200/stoptest/_search?pretty=true" -d ' | |
{ | |
"query":{ | |
"term":{ | |
"test_length":"lazy" | |
} | |
} | |
} | |
' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment