Skip to content

Instantly share code, notes, and snippets.

@amejiarosario
Forked from acreeger/gist:1027916
Last active December 20, 2015 04:29
Show Gist options
  • Save amejiarosario/6070937 to your computer and use it in GitHub Desktop.
Save amejiarosario/6070937 to your computer and use it in GitHub Desktop.
curl -XDELETE http://localhost:9200/ac-test
#curl -XPUT http://localhost:9200/ac-test
# --- Mapping ---
curl -XPOST 'http://localhost:9200/ac-test
'{"mappings" : { {
"people" : {
"properties" : {
"firstNames" : {
"type" : "string"
},
"lastName" : {
"type" : "string"
},
"location" : {
"type" : "string"
},
"macaddr" : {
"type" : "string",
"index":"not_analyzed"
}
}
}
}}'
curl -XPUT http://localhost:9200/ac-test/people/1 -d '
{
"firstNames" : "James Earl",
"lastName" : "Jones",
"location" : "Hollywood, CA"
}'
curl -XPUT http://localhost:9200/ac-test/people/2 -d '
{
"firstNames" : "Earl",
"lastName" : "Grey",
"location" : "London, UK"
}'
curl -XPUT http://localhost:9200/ac-test/people/3 -d '
{
"firstNames" : "James Maxwell",
"lastName" : "Earl",
"location" : "Portland, OR"
}'
curl -XPOST 'http://localhost:9200/ac-test/_refresh'
# curl -XGET 'http://localhost:9200/ac-test/people/_mapping?pretty
#-----------------------------
echo 'We expect 2 hits from this'
curl -XPOST http://localhost:9200/ac-test/people/_search -d '
{
"query" : {
"query_string" : {
"fields": ["firstNames","lastName","location"],
"query":"James Earl",
"default_operator" : "AND"
}
}
}
'
echo 'We expect 1 hit from this'
curl -XPOST http://localhost:9200/ac-test/people/_search -d '
{
"query" : {
"query_string" : {
"fields": ["firstNames","lastName","location"],
"query":"\"James Earl\"",
"default_operator" : "AND"
}
}
}
'
echo 'We expect 1 hit from this'
curl -XPOST http://localhost:9200/ac-test/people/_search -d '
{
"query" : {
"query_string" : {
"fields": ["firstNames","lastName","location"],
"query":"James Portland",
"default_operator" : "AND"
}
}
}
'
echo And this errors...
curl -XPOST http://localhost:9200/ac-test/people/_search -d '
{
"query" : {
"query_string" : {
"fields": ["firstNames","lastName","location"],
"query":"\"James Maxwell\" Portland, OR",
"default_operator" : "AND"
}
}
}
'
# In order to fix the error, we could use a text query. But what are the equivalent queries using a text query?
# If the purpose of the text query is to meet the needs of a search box used by the general public, wouldn't this be a better interface?
# curl -XPOST http://localhost:9200/ac-test/people/_search -d '
# {
# "query" : {
# "text" : {
# "fields": ["firstNames","lastName","location"],
# "query":"\"James Maxwell\" Portland, OR",
# "default_operator" : "AND"
# }
# }
# }
# '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment