Allow user to search "-". like QNAM-109

Hi All,

In our project, system allows user to search text which may contain "-".
For example user enter QNAM-109 as search text and ES should retrieve all
docs which contains QNAM-109 as value of any of field of those docs.
further more ES should return all documents whose fields' value start with
QNAM-109.

For above requirement I created index in following way.

{
"settings": {
"index": {
"number_of_shards": 8,
"number_of_replicas": 0,
"analysis": {
"analyzer": {
"uax_url_email": {
"filter": [
"standard",
"lowercase",
"stop"
],
"tokenizer": "uax_url_email"
},
"whitespace": {
"tokenizer": "whitespace",
"filter": [
"standard",
"lowercase",
"stop"
]
}
}
}
}
},
"mappings": {
"quotation": {
"_source": {
"enabled": true
},
"properties": {
"QuotationNo": {
"type": "string",
"analyzer": "whitespace"
},
"Status": {
"type": "string"
},
"CreateDate": {
"type": "string",
"index": "no"
},
"ExpiryDate": {
"type": "string",
"index": "no"
},
"FirstName": {
"type": "string",
"index": "no"
},
"LastName": {
"type": "string"
},
"EmailIds": {
"type": "string",
"analyzer": "uax_url_email"
},
"CellNumbers": {
"type": "string"
}
}
}
}
}


Here my sample data that I inserted in ES

{
"Status" :"Active",
"QuotationNo": "qnam-1099",
"EmailIds" : [ "vyas@s.com"],
"FirstName": "yasop",
"LastName": "qexhd",
"CellNumbers" : ["852456"]
}

{
"Status" :"Active",
"QuotationNo": "qnam-1095",
"EmailIds" : [ "qhul@aber.com"],
"FirstName": "qhul",
"LastName": "uiox",
"CellNumbers" : ["581236"]
}

{
"Status" :"Active",
"QuotationNo": "qnam-1081",
"EmailIds" : [ "poxr@poxr.com"],
"FirstName": "poxr",
"LastName": "poxr",
"CellNumbers" : ["895255"]
}

Now I fire following search query. I am expecting all documents whose
fields' value start with qnam-109.

{
"from": "0",
"size": "10",
"query": {
"query_string": {
"default_field": "_all",
"default_operator": "AND",
"analyze_wildcard": true,
"query": "qnam-109*"
}
}
}

Above query should returns only two documents out of three documents that I
inserted in ES. As one document contains qnam-1081. But unfortunately
previous query returns all documents. It also fetch document with qnam-1081
in "QuotationNo".
Can anyone please suggest what I am doing wrong? Or can anyone suggest ES
queries to create index and search from index which may contain "-" in any
one field of a type within that index.

Note:- Our search UI contains only one search text box like Google. User
enter anything to search from index. and search query should find all types
of Index that satisfies search text. That is the reason I have created
search query like above.
second thing some of field of document may contain email address. and we
also giving facility to user to find document from email address. that is
why I used uax_url_email as analyzer also.

Thanks and Regards

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hey,

you might want to take a closer look at the match and the prefix queries
and play around with those.

--Alex

On Thu, Jul 25, 2013 at 6:35 PM, hdvyas hdvyas007@gmail.com wrote:

Hi All,

In our project, system allows user to search text which may contain "-".
For example user enter QNAM-109 as search text and ES should retrieve all
docs which contains QNAM-109 as value of any of field of those docs.
further more ES should return all documents whose fields' value start with
QNAM-109.

For above requirement I created index in following way.

{
"settings": {
"index": {
"number_of_shards": 8,
"number_of_replicas": 0,
"analysis": {
"analyzer": {
"uax_url_email": {
"filter": [
"standard",
"lowercase",
"stop"
],
"tokenizer": "uax_url_email"
},
"whitespace": {
"tokenizer": "whitespace",
"filter": [
"standard",
"lowercase",
"stop"
]
}
}
}
}
},
"mappings": {
"quotation": {
"_source": {
"enabled": true
},
"properties": {
"QuotationNo": {
"type": "string",
"analyzer": "whitespace"
},
"Status": {
"type": "string"
},
"CreateDate": {
"type": "string",
"index": "no"
},
"ExpiryDate": {
"type": "string",
"index": "no"
},
"FirstName": {
"type": "string",
"index": "no"
},
"LastName": {
"type": "string"
},
"EmailIds": {
"type": "string",
"analyzer": "uax_url_email"
},
"CellNumbers": {
"type": "string"
}
}
}
}
}


Here my sample data that I inserted in ES

{
"Status" :"Active",
"QuotationNo": "qnam-1099",
"EmailIds" : [ "vyas@s.com"],
"FirstName": "yasop",
"LastName": "qexhd",
"CellNumbers" : ["852456"]
}

{
"Status" :"Active",
"QuotationNo": "qnam-1095",
"EmailIds" : [ "qhul@aber.com"],
"FirstName": "qhul",
"LastName": "uiox",
"CellNumbers" : ["581236"]
}

{
"Status" :"Active",
"QuotationNo": "qnam-1081",
"EmailIds" : [ "poxr@poxr.com"],
"FirstName": "poxr",
"LastName": "poxr",
"CellNumbers" : ["895255"]
}

Now I fire following search query. I am expecting all documents whose
fields' value start with qnam-109.

{
"from": "0",
"size": "10",
"query": {
"query_string": {
"default_field": "_all",
"default_operator": "AND",
"analyze_wildcard": true,
"query": "qnam-109*"
}
}
}

Above query should returns only two documents out of three documents that
I inserted in ES. As one document contains qnam-1081. But unfortunately
previous query returns all documents. It also fetch document with qnam-1081
in "QuotationNo".
Can anyone please suggest what I am doing wrong? Or can anyone suggest ES
queries to create index and search from index which may contain "-" in any
one field of a type within that index.

Note:- Our search UI contains only one search text box like Google. User
enter anything to search from index. and search query should find all types
of Index that satisfies search text. That is the reason I have created
search query like above.
second thing some of field of document may contain email address. and we
also giving facility to user to find document from email address. that is
why I used uax_url_email as analyzer also.

Thanks and Regards

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.