Hi all,
Can anyone please help me on this issue? I'm trying to find an e-mail
with elasticsearch but can't seem to get it to work properly.
I've created an index with the following mapping:
$ curl -s -XPUT http://localhost:9200/users/info/_mapping -d '
{
"info" : {
"properties": {
"name" : {
"type": "multi_field",
"fields" : {
"name": {
"type" : "string"
},
"untouched" : {
"type": "string",
"index" : "not_analyzed"
}
}
},
"email" : {"type" : "string", "analyzer":"keyword"}
}
}
}'
Add two documents:
$ curl -XPUT http://localhost:9200/users/info/1 -d '{
"user": "user1",
"email": "user1@email.com",
"message": "Testing"
}'
$ curl -XPUT http://localhost:9200/users/info/2 -d '{
"user": "user2",
"email": "user2@email.com",
"message": "Programming"
}'
Note: I set the email analyzer to "keyword" because in the
presentation http://www.slideshare.net/clintongormley/terms-of-endearment-the-elasticsearch-query-dsl-explained
it is showed that the email is set as a token with this analyzer.
And then I've created the following query:
$ curl -XGET 'http://localhost:9200/users/info/_search?pretty=1' -d '
{
"query" : {
"filtered" : {
"query" : { "match_all" : {} },
"filter" : {
"and" : [
{ "term" : { "_all" : "user1@email.com" } },
{ "not": { "filter" : { "ids" : { "values" :
[ "400" ] } } } }
]
}
}
}
}'
But it doesn't work. The result is empty.
I've checked that this query work if I one another field (the name for
instance):
$ curl -XGET 'http://localhost:9200/users/info/_search?pretty=1' -d '
{
"query" : {
"filtered" : {
"query" : { "match_all" : {} },
"filter" : {
"and" : [
{ "term" : { "_all" : "user1" } },
{ "not": { "filter" : { "ids" : { "values" :
[ "400" ] } } } }
]
}
}
}
}'
It also works if I try to find only in the field "name":
curl -XGET 'http://localhost:9200/users/info/_search?pretty=1' -d '
{
"query" : {
"filtered" : {
"query" : { "match_all" : {} },
"filter" : {
"and" : [
{ "term" : { "email" : "user1@email.com" } },
{ "not": { "filter" : { "ids" : { "values" :
[ "400" ] } } } }
]
}
}
}
}'
Thanks for your help.
Best regards,
Hugo