Problem with should boolean search request


(smhdiu) #1

hello all

i am searching using the following string

curl -XGET http://localhost:9200/contactsearch/_search?pretty=truee -d '{
"query" :
{
"bool" : {
"should" : [ {
"term" : {
"email" : "smhdiu@gmail.com"
}
}, {
"term" : {
"firstName" : "Mohsin"
}
}, {
"term" : {
"lastName" : "Husen"
}
} ]
}
}}'

but i am not getting any result in searchresponce where as i have following
record in index

{"id":8891179303112017,"journalId":10155,
"title":"Dr","firstName":"Mohsin","initials":null,
"lastName":"Husen","status":null,"email":"smhdiu@gmail.com" }

please suggest

any help will be greatly appreciated.

Mohsin H

--


(Tanguy) #2

If no mappings are defined, elasticsearch wil use a standard analyzer when
indexing/searching the documents.

The string fields of your document go through an analysis process,
and "Mohsin" becomes "mohsin", "Husen" => "husen", "smh...@gmail.com" =>
"smh.. gmail.com"

To learn more on analysis:
http://www.elasticsearch.org/guide/reference/index-modules/analysis/index.html

If you want to find your document, the simpliest way if to use
a query_string query, which will analyze your search keywords:
http://localhost:9200/contactsearch/_search?q=Husen

If you wan to keep your boolean query, you can use query_string or field
queries instead of term queries:
{
"query": {
"bool": {
"should": [
{
"term": {
"email": "smh...@gmail.com"
}
},
{
"field": {
"firstName": "Mohsin"
}
},
{
"field": {
"lastName": "Husen"
}
}
]
}
}
}

Since you are searching for email addresses, you should definitely use a
specific mapping for your document type and look at UAX Url Email Tokenizer
http://www.elasticsearch.org/guide/reference/index-modules/analysis/uaxurlemail-tokenizer.html

-- Tanguy

Le lundi 5 novembre 2012 16:54:28 UTC+1, mohsin husen a écrit :

hello all

i am searching using the following string

curl -XGET http://localhost:9200/contactsearch/_search?pretty=truee -d '{
"query" :
{
"bool" : {
"should" : [ {
"term" : {
"email" : "smh...@gmail.com <javascript:>"
}
}, {
"term" : {
"firstName" : "Mohsin"
}
}, {
"term" : {
"lastName" : "Husen"
}
} ]
}
}}'

but i am not getting any result in searchresponce where as i have
following record in index

{"id":8891179303112017,"journalId":10155,
"title":"Dr","firstName":"Mohsin","initials":null,
"lastName":"Husen","status":null,"email":"smh...@gmail.com <javascript:>"
}

please suggest

any help will be greatly appreciated.

Mohsin H

--


(system) #3