On Wed, 2011-05-04 at 04:18 -0700, senthil prabhu wrote:
Ya you are exactly right...
1.) What type of mapping that i need to use to get the full email
while search?
or what type search query that i need to use instead of term
query ?
You have a few choices.
With your existing mapping, if your mail_from field contains exactly one
email address, then you could use a query string search, and put the
email address into double quotes, eg: '"senthil@gmail.com"'
However that would also find "foobar.senthil@gmail.com"
So if you want to use the email address as a unique ID, you probably do
want to do a term query, and you could set the mail_from property to
{"type": "string", "index":"not_analyzed"}
However, the term "senthil@gmail.com" is not the same as the term
"Senthil@GMAIL.com"
So make sure that you lowercase both the data that you index, and the
term that you search for. (and you may need to trim any leading or
trailing whitespace as well)
Also, would you want to do searches for any email address containing
"senthil" or "gmail"?
If so, then you need both the not_analyzed field, and an analyzed field.
You could do this with a multi field:
curl -XPUT 'http://127.0.0.1:9200/foo/email/_mapping?pretty=1' -d '
{
"email" : {
"properties" : {
"mail_from" : {
"fields" : {
"id" : {
"index" : "not_analyzed",
"type" : "string"
},
"mail_from" : {
"index" : "analyzed",
"type" : "string"
}
},
"type" : "multi_field"
}
}
}
}
'
See Elasticsearch Platform — Find real-time answers at scale | Elastic
Then you can use these as follows:
Search for "gmail":
curl -XGET 'http://127.0.0.1:9200/foo/mail/_search?pretty=1' -d '
{
"query" : {
"field" : {
"mail_from" : "gmail"
}
}
}
'
curl -XGET 'http://127.0.0.1:9200/foo/mail/_search?pretty=1' -d '
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"mail_from.id" : "senthil@gmail.com"
}
}
}
}
}
'
clint