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