# Custom Plugins in Elasticsearch

**URL:** <https://discuss.elastic.co/t/custom-plugins-in-elasticsearch/328432>\
**Category:** Elasticsearch\
**Created:** [March 24, 2023, 7:50am UTC](https://discuss.elastic.co/t/custom-plugins-in-elasticsearch/328432 "2023-03-24T07:50:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![JAYAVARDHAN\_VEJENDLA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayavardhan_vejendla/32/118869_2.png) [@JAYAVARDHAN\_VEJENDLA](https://discuss.elastic.co/u/JAYAVARDHAN_VEJENDLA)\
**Post date:** [March 24, 2023, 7:50am UTC](https://discuss.elastic.co/t/custom-plugins-in-elasticsearch/328432/1 "2023-03-24T07:50:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [March 24, 2023, 10:24am UTC](https://discuss.elastic.co/t/custom-plugins-in-elasticsearch/328432/2 "2023-03-24T10:24:15Z")

</div>

Hi @JAYAVARDHAN_VEJENDLA,

Welcome to the community! Check out our [plugin author guide](https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugin-authors.html) which has information and a link to examples.

---

<div class="post-metadata">

**Author:** ![JAYAVARDHAN\_VEJENDLA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayavardhan_vejendla/32/118869_2.png) [@JAYAVARDHAN\_VEJENDLA](https://discuss.elastic.co/u/JAYAVARDHAN_VEJENDLA)\
**Post date:** [March 27, 2023, 9:23am UTC](https://discuss.elastic.co/t/custom-plugins-in-elasticsearch/328432/3 "2023-03-27T09:23:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JAYAVARDHAN\_VEJENDLA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayavardhan_vejendla/32/118869_2.png) [@JAYAVARDHAN\_VEJENDLA](https://discuss.elastic.co/u/JAYAVARDHAN_VEJENDLA)\
**Post date:** [March 27, 2023, 9:45am UTC](https://discuss.elastic.co/t/custom-plugins-in-elasticsearch/328432/4 "2023-03-27T09:45:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [March 27, 2023, 10:48am UTC](https://discuss.elastic.co/t/custom-plugins-in-elasticsearch/328432/5 "2023-03-27T10:48:35Z")

</div>

Hi @JAYAVARDHAN_VEJENDLA,

Not sure if this helps, but I did find a [related post](https://discuss.elastic.co/t/poximity-search-with-wildcards-and-phrase-multiple-word-terms/228360) 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](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/index.html).

---

<div class="post-metadata">

**Author:** ![JAYAVARDHAN\_VEJENDLA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayavardhan_vejendla/32/118869_2.png) [@JAYAVARDHAN\_VEJENDLA](https://discuss.elastic.co/u/JAYAVARDHAN_VEJENDLA)\
**Post date:** [March 27, 2023, 11:06am UTC](https://discuss.elastic.co/t/custom-plugins-in-elasticsearch/328432/6 "2023-03-27T11:06:00Z")

</div>

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"  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![William\_Brafford](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/william_brafford/32/51559_2.png) [@William\_Brafford](https://discuss.elastic.co/u/William_Brafford)\
**Post date:** [March 27, 2023, 2:44pm UTC](https://discuss.elastic.co/t/custom-plugins-in-elasticsearch/328432/7 "2023-03-27T14:44:47Z")

</div>

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](https://lucene.apache.org/core/9_5_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html), 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](https://lucene.apache.org/core/9_5_0/queryparser/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.html). 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](https://github.com/elastic/elasticsearch/blob/main/x-pack/plugin/search-business-rules/src/main/java/org/elasticsearch/xpack/searchbusinessrules/SearchBusinessRules.java) 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.

---

<div class="post-metadata">

**Author:** ![JAYAVARDHAN\_VEJENDLA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayavardhan_vejendla/32/118869_2.png) [@JAYAVARDHAN\_VEJENDLA](https://discuss.elastic.co/u/JAYAVARDHAN_VEJENDLA)\
**Post date:** [March 27, 2023, 3:05pm UTC](https://discuss.elastic.co/t/custom-plugins-in-elasticsearch/328432/8 "2023-03-27T15:05:32Z")

</div>

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.

---

<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:** [April 24, 2023, 3:06pm UTC](https://discuss.elastic.co/t/custom-plugins-in-elasticsearch/328432/9 "2023-04-24T15:06:00Z")

</div>

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