Created
December 6, 2012 23:13
-
-
Save drewr/4229326 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
#!/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