Custom Plugins in Elasticsearch

Hello everyone! We are using Elasticsearch in the Legal and Investigation area. We need to perform Proximity and Wildcard Search in a single query-string query, and we found out that elasticsearch is not providing that feature. So we planned to create a new custom plugin. Can anyone provide the documentation for creating the custom plugin for elasticsearch.

Hi @JAYAVARDHAN_VEJENDLA,

Welcome to the community! Check out our plugin author guide which has information and a link to examples.

This is not enough. I need the documentation of how to write the java code for the elasticsearch plugin

Hi Carmon,

I want to perform the proximity and wildcard search in the query string query. Something like

GET /_search{
query:{
"query_string":{
"query":"hel* wor*~5"
}
}
}

It should match the documents with "hel*" and "wor*" with the slop value as 5.

I have checked the entire query_string query documentation and I got to know that it's not possible to combine the wildcard and proximity in the single query_string query.

Can you please help me to solve this by using only the querystring query.

Hi @JAYAVARDHAN_VEJENDLA,

Not sure if this helps, but I did find a related post on proximity search with wildcard and terms that might be worth a look to see if it helps with your issue. If that approach is helpful it might mean you don't need to write the plugin.

As an aside, if you're looking for documentation on writing Java code connecting to Elasticsearch, I would have a look at the Elasticsearch Java API client documentation.

Thanks for the help Carly.
I actually also want the features of the query-string query in elasticsearch. But here they are using the span-near query.
Can you please provide me the solution using the query-string query.
Eg:
GET /_search{
query:{
"query_string":{
"query":"hel* wor*~5 AND thank"
}
}
}

The problem is a little bit more general than an incompatibility between proximity searches and wildcard searches. It is that wildcards are not allowed within phrases, and proximity searches only operate on phrases. Our query string parsing comes from Lucene's classic query parser, which doesn't support wildcards within phrases. This is a pretty basic element of the query syntax.

Lucene does have a query parser that can do what you want: the ComplexPhraseQueryParser. If you wanted to use this, you would have to build a Search Plugin that implements a new query type (overriding the getQueries method, see the search-business-rules plugin for an example), and figure out how to delegate to the complex parser. If you wanted to match the existing API for query strings in Elasticsearch, you would have to reimplement it yourself. Your plugin would also be potentially subject to breaking changes between Elasticsearch versions. This is all possible, but it could be quite a project.

For a stable and well-tested alternative, I would highly recommend finding a way to use Elasticsearch's full query DSL, especially span queries, as @carly.richmond recommended.

2 Likes

Thank you very much. We have actually planned to do the same (Create a new custom plugin and using the ComplexPhraseQueryParser from Lucene engine). We tried to create a plugin and override the getQueries method, but it is showing some error(Cannot infer type arguments : QuerySpec<>). If you help us resolving the issue, it will be very grateful.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.