# Custom OpenSearch Highlighter Plugin

**URL:** <https://forum.opensearch.org/t/custom-opensearch-highlighter-plugin/7572>\
**Category:** OpenDistro\
**Created:** [November 11, 2021, 8:48am UTC](https://forum.opensearch.org/t/custom-opensearch-highlighter-plugin/7572 "2021-11-11T08:48:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![asfoorial](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@asfoorial](https://forum.opensearch.org/u/asfoorial)\
**Post date:** [November 11, 2021, 8:48am UTC](https://forum.opensearch.org/t/custom-opensearch-highlighter-plugin/7572/1 "2021-11-11T08:48:23Z")

</div>

Greetings all,

I have been trying to create a custom highlighter by creating a plugin that implements SearchPlugin, getHighlighter() method and create my own CustomHighlighter class that implements the Highlighter interface and its highlight() method.  
My logic needs to check the user query to determine what should be highlighted.

Question: How can I get the user query from within SearchPlugin.getHighlighter() method and/or the CustomHighlighter?  
(the whole REST request body is preferred).

Your help is highly appreciated.

---

<div class="post-metadata">

**Author:** ![anirudha](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/anirudha/32/5647_2.png) [@anirudha](https://forum.opensearch.org/u/anirudha)\
**Post date:** [November 18, 2021, 8:18pm UTC](https://forum.opensearch.org/t/custom-opensearch-highlighter-plugin/7572/2 "2021-11-18T20:18:00Z")

</div>

> [@asfoorial](#):
>
> getHighlighter

> <https://github.com/opensearch-project/OpenSearch/blob/0ba0e7cc26060f964fcbf6ee45bae53b3a9941d0/plugins/examples/custom-suggester/src/main/java/org/opensearch/example/customsuggester/CustomSuggester.java#L46>

try this example to replicate

---

<div class="post-metadata">

**Author:** ![asfoorial](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@asfoorial](https://forum.opensearch.org/u/asfoorial)\
**Post date:** [November 18, 2021, 9:06pm UTC](https://forum.opensearch.org/t/custom-opensearch-highlighter-plugin/7572/3 "2021-11-18T21:06:43Z")

</div>

Thanks.

But I dont see how this is related to highlighting. I mainly need to access the user query from within getHighlights method or any equivalent method.
