Skip to content

Instantly share code, notes, and snippets.

@drewr
Created December 6, 2012 23:13
Show Gist options
  • Save drewr/4229326 to your computer and use it in GitHub Desktop.
Save drewr/4229326 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo Deleting index if it exists
curl -s -XDELETE localhost:9200/blue-sky-monster >/dev/null
echo Creating test index
curl -s -XPUT localhost:9200/blue-sky-monster -d '
{
"mappings": {
"user": {
"properties": {
"first_name": {
"fields": {
"first_name": {
"analyzer": "full_name",
"type": "string"
}
},
"type": "multi_field"
},
"last_name": {
"fields": {
"last_name": {
"analyzer": "full_name",
"type": "string"
}
},
"type": "multi_field"
}
}
}
},
"settings": {
"analysis": {
"analyzer": {
"full_name": {
"filter": [
"standard",
"lowercase",
"asciifolding"
],
"tokenizer": "standard",
"type": "custom"
}
}
}
}
}
'
echo
echo Populating test index
curl -s -XPUT localhost:9200/blue-sky-monster/user/1 -d '
{
"first_name": "John",
"last_name": "John"
}'
echo
curl -s -XPUT localhost:9200/blue-sky-monster/user/2 -d '
{
"first_name": "John",
"last_name": "Smith"
}'
echo
curl -s -XPUT localhost:9200/blue-sky-monster/user/3 -d '
{
"first_name": "John",
"last_name": "Sánchez"
}'
echo
curl -s -XPUT localhost:9200/blue-sky-monster/user/4 -d '
{
"first_name": "Joe John",
"last_name": "Smitt"
}'
echo
echo
echo Done
curl -s -XPOST localhost:9200/blue-sky-monster/_refresh
echo
echo "User searches for 'John Smith' in search bar"
echo "Expected result 'John Smith' first"
echo "Actual result:"
curl -s localhost:9200/blue-sky-monster/_search\?pretty=1 -d '
{
"query": {
"bool": {
"should": [
{
"text": {
"first_name": "John Smith"
}
},
{
"text": {
"last_name": "John Smith"
}
}
]
}
}
}
'
echo
echo "User searches for 'John Sánchez' in search bar"
echo "Expected result 'John Sánchez' first"
echo "Actual result:"
curl -s localhost:9200/blue-sky-monster/_search\?pretty=1 -d '
{
"query" : {
"bool" : {
"should" : [
{
"text" : {
"first_name" : "John Sánchez"
}
},
{
"text" : {
"last_name" : "John Sánchez"
}
}
]
}
}
}
'
echo
curl -s localhost:9200/blue-sky-monster/_search\?pretty=1 -d '
{
"query": {
"query_string": {
"query": "john smith"
}
}
}
'
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment