Skip to content

Instantly share code, notes, and snippets.

@blueskymonster
Created December 6, 2012 21:36
Show Gist options
  • Save blueskymonster/4228704 to your computer and use it in GitHub Desktop.
Save blueskymonster/4228704 to your computer and use it in GitHub Desktop.
A rather contrived example of an issue I'm running into trying to use one string to search over first and last names together
#!/bin/bash
echo 'Deleting index if it exists'
curl -XDELETE 'http://127.0.0.1:9200/test'
echo
echo 'Creating test index'
curl -XPUT 'http://127.0.0.1:9200/test/?pretty=1' -d '
{
"mappings" : {
"user" : {
"properties" : {
"last_name" : {
"fields" : {
"last_name" : {
"type" : "string",
"analyzer" : "full_name"
}
},
"type" : "multi_field"
},
"first_name" : {
"fields" : {
"first_name" : {
"type" : "string",
"analyzer" : "full_name"
}
},
"type" : "multi_field"
}
}
}
},
"settings" : {
"analysis" : {
"analyzer" : {
"full_name" : {
"filter" : [
"standard",
"lowercase",
"asciifolding"
],
"type" : "custom",
"tokenizer" : "standard"
}
}
}
}
}'
echo
echo 'Populating test index'
curl -XPOST 'http://127.0.0.1:9200/_bulk?pretty=1' -d '
{"index" : {"_index" : "test", "_type" : "user"}}
{"last_name" : "John", "first_name" : "John"}
{"index" : {"_index" : "test", "_type" : "user"}}
{"last_name" : "Smith", "first_name" : "John"}
{"index" : {"_index" : "test", "_type" : "user"}}
{"last_name" : "Sánchez", "first_name" : "John"}
{"index" : {"_index" : "test", "_type" : "user"}}
{"last_name" : "Smitt", "first_name" : "Joe John"}
{"index" : {"_index" : "test", "_type" : "user"}}
{"last_name" : "John", "first_name" : "Smith"}
'
echo
echo 'Done'
#!/bin/bash
echo
echo "User searches for 'John Smith' in search bar"
echo "Expected result 'John Smith' first"
echo "Actual result:"
curl -XGET 'http://127.0.0.1:9200/test/user/_search?pretty=1' -d '
{
"query" : {
"bool" : {
"should" : [
{
"text" : {
"first_name" : "John Smith"
}
},
{
"text" : {
"last_name" : "John Smith"
}
}
]
}
}
}
'
echo
echo
echo "User searches for 'John Sánchez' in search bar"
echo "Expected result 'John Sánchez' first"
echo "Actual result:"
curl -XGET 'http://127.0.0.1:9200/test/user/_search?pretty=1' -d '
{
"query" : {
"bool" : {
"should" : [
{
"text" : {
"first_name" : "John Sánchez"
}
},
{
"text" : {
"last_name" : "John Sánchez"
}
}
]
}
}
}
'
echo
echo
echo "User searches for 'Smith John' in search bar"
echo "Expected result 'Smith John' first"
echo "Actual result:"
curl -XGET 'http://127.0.0.1:9200/test/user/_search?pretty=1' -d '
{
"query" : {
"bool" : {
"should" : [
{
"text" : {
"first_name" : "Smith John"
}
},
{
"text" : {
"last_name" : "Smith John"
}
}
]
}
}
}
'
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment