# ElasticSearch in Grails, search return no results when domain field has value with @ character

**URL:** <https://discuss.elastic.co/t/elasticsearch-in-grails-search-return-no-results-when-domain-field-has-value-with-character/21459>\
**Category:** Elasticsearch\
**Created:** [January 2, 2015, 7:23pm UTC](https://discuss.elastic.co/t/elasticsearch-in-grails-search-return-no-results-when-domain-field-has-value-with-character/21459 "2015-01-02T19:23:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kamil\_W](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Kamil\_W](https://discuss.elastic.co/u/Kamil_W)\
**Post date:** [January 2, 2015, 7:23pm UTC](https://discuss.elastic.co/t/elasticsearch-in-grails-search-return-no-results-when-domain-field-has-value-with-character/21459/1 "2015-01-02T19:23:30Z")

</div>

Hello,

I encountered a problem when I was changing Searchable plugin to  
ElasticSearch plugin (:elasticsearch:0.0.3.8) for Grails (2.4.4).

Let's say that I have domain object and a service:

class Person {  
String firstName  
String lastName  
String email  
static constraints = {  
id bindable: true  
firstName blank: false  
lastName blank: false  
email blank: false, unique: true, email: true  
}  
static searchable = {  
root true  
only = ['id', 'firstName', 'lastName', 'email']  
}  
}

class SearchService {

```
List<Person> findPersons(String searchPhrase) {
    Innovator.search(searchPhrase + '*').searchResults
}

```

}

My Config.groovy file contains following config:

elasticSearch {  
client.mode = 'local'  
index.store.type = 'memory'  
date.formats = []  
defaultExcludedProperties = ["password"]  
disableAutoIndex = false  
datastoreImpl = 'hibernateDatastore'  
bulkIndexOnStartup = true  
maxBulkRequest = 500  
}

Suppose that we have following person in DB:

Person(firstName: 'Julius', lastName: 'Caesar', email:  
'julius.caesar@domain.com')

Now, when I invoke findPersons('Julius') or findPersons('Caesar') or  
findPersons('Jul') etc. then as a result I get list with one Person object.  
But when I try to search using phrase with '@' character for example:  
findPersons('julius.caesar@doma') or findPersons('julius.caesar@domain.com')  
_I do not receive any results_, hovever findPersons('julius.caesar') is ok.  
Analogical code in Searchable plugin works correct.

I've tried to remove '\*' character and it didn't help.

As workaround I changed searchable closure to:  
static searchable = {  
root true  
email index : 'not\_analyzed'  
only = ['id', 'firstName', 'lastName', 'email']  
}

and findPersons method to:  
List findPersons(String searchPhrase) {  
if(!searchPhrase.contains('@'){  
searchPhrase += '\*'  
}  
Innovator.search(searchPhrase).searchResults  
}

Now I can use findPersons('julius.caesar@domain.com') to find Person  
object. But this is exact value and I would like to use also prefix search  
for email field.  
For example: findPersons('julius.caesar@doma') should also return Person as  
a result.

Thank you for any tips and any help in solving this issue.

Regards,  
Kamil

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/50e30fc4-0d64-4ae9-b230-5877cfc25100%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/50e30fc4-0d64-4ae9-b230-5877cfc25100%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:41am UTC](https://discuss.elastic.co/t/elasticsearch-in-grails-search-return-no-results-when-domain-field-has-value-with-character/21459/2 "2017-07-06T00:41:06Z")

</div>


