Is it possible to access mysql server in script filter with groovy

(Yehua984710) #1

I want to access our mysql server in groovy script filter to do some query with value of some fields. Is it possible to do this?

(Colin Goodheart-Smithe) #2

I'm not sure whether this is possible (probably is somehow) but accessing an other datastore during the search process is a bad idea and you should avoid doing this as it will kill the search performance. I would instead perform a search in Elasticsearch with the other filter criteria and then have some post processing in your application that further filters based on the contents of your mysql tables.

Alternatively I would add the information you want to filter on in the mysql database to the documents as part of your indexing process.

(Yehua984710) #3

thanks for the suggestion. I agree it is not a good idea to do this. The reason why I did not index the info in mysql to elasticsearch is such info is mutable. The cost to update the value in mysql is much cheap. It is painful to do this in elasticsearch

(Yehua984710) #4

Anybody can tell more insight?

(Nik Everett) #5

You could do it but it'll be lots slower. I'd just write it as a native
script plugin with mysql driver as the dependency.

(Yehua984710) #6

Thank you, Nik. So I got some concrete questions. In which folder i need to put the mysql driver for groovy to import? And how to set the class path for groovy filter script? Could you help?

(Nik Everett) #7

I'm not sure. As I said if I were to do this then I'd write a plugin. And I
wouldn't do it because it'll be super slow.

(Yehua984710) #8

OK. Thank you.

(system) #9