How can have a custom TransportAction which runs for each index request like TransportReplicationAction?

(Mahdi Malaki) #1

I need something like filter's in servlet containers so that catch arrived request before launching indexing process. When I debugged elastic source code, I found TransportReplicationAction is called and i'd like to have something like that in my plugin. Of course, if there is a way that I can have a custom DefaultIndexingChain in my plugin, it will be very useful.

(Jörg Prante) #2

You can implement your own "index" command in a plugin, with your preferred custom primary shard/replication action management.

Extending the existing indexing action is not possible so you would have to copy/paste much code.

(Mahdi Malaki) #3

ِDear @jprante many thanks for your reply. Can you refer to a document or snip of code which help me?

(Mahdi Malaki) #4

@jprante In fact, I am looking for a way so that let me to pass a parameter to my custom Analyzer at indexing time. What is the best solution? This is why I came to the idea that I implement a custom Action. Right now, I implemented my custom Action, But there is tow problems: the first is that I don't know How I can register this Action so that it automatically called for every request for indexing. Secondly, Is this solution is the best way for my problem?

(Jörg Prante) #5

@mahdi_malaki You don't need a custom index operation just for applying a custom analyzer. Custom analyzers can be registered and integrated into ES without hassles.

(Mahdi Malaki) #6

@jprante I have known that it is easy to integrate a typical analyzer into elastic as a plugin. But my analyzer expect to restive a special parameter from the client as well as indexing data. My problem is that how I can pass this parameter?
When I debug my analyzer, I see that the analyzer just access to field name along with its data. While I need to access a parameter that is attached to request.

(Jörg Prante) #7

@mahdi_malaki can you show an example what you want you achieve? Note that an analyzer can not have access to the indexing., because the phase of analyzing (token stream generation) is happening before, independent of the index machinery (shards, replica, etc.)

(Mahdi Malaki) #8

@jprante OK, I have a custom analyzer that try to automatically detect the language used in the data field. But sometimes I need to send the client language to the analyzer for indexing along with the document. I can set the language as a separated field in my document which is supposed to be indexed, but the analyzer can't access to the lang field while attempting to index another field.

(Jörg Prante) #9

It looks like you want to implement a custom field type. The phase where you can access the field plus the whole document source is the field mapper, not the analyzer.

(Mahdi Malaki) #10

Thank @jprante, I handled the problem through registering a TypeParser as you defined in your plugin. It lets me to access to the special filed value before analyzing phase. Then I set the lang field in a thread local variable and try to read in my analyzer. This approach is not ideal but works.

(system) #11