# How to get the terms of the query text in the plugin code?

**URL:** <https://discuss.elastic.co/t/how-to-get-the-terms-of-the-query-text-in-the-plugin-code/156433>\
**Category:** Elasticsearch\
**Created:** [November 13, 2018, 10:03am UTC](https://discuss.elastic.co/t/how-to-get-the-terms-of-the-query-text-in-the-plugin-code/156433 "2018-11-13T10:03:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![liuxuanfei](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/liuxuanfei/32/37572_2.png) [@liuxuanfei](https://discuss.elastic.co/u/liuxuanfei)\
**Post date:** [November 13, 2018, 10:03am UTC](https://discuss.elastic.co/t/how-to-get-the-terms-of-the-query-text-in-the-plugin-code/156433/1 "2018-11-13T10:03:12Z")

</div>

First of all, I must apologize for my poor English.😂

I want to write a plugin to return script score (based on Levenshtein Distance) for each hit.

e.g.  
{  
"query": {  
"match" : {  
"message" : "The 2 QUICK Brown-Foxes"  
}  
},  
"script\_fields" : {  
"new\_score" : {  
"script" : {  
"lang": "my\_expert\_scripts",  
"source": "pure\_ld",  
"params": { ... }  
}  
}  
}  
}

In the plugin's java code , how can I get the terms of the query text that it has be analyzed (e.g. "quick brown fox" in the above example) ?

I have two ideas:  
One is to view the terms of the query text through the analyzer api, then pass the terms to the plugin by using `params`. But this way led to two remote requests.  
The other one, is it possible to analyze the query text directly in the plugin code by an specified analyzer?

Besides, is there any other better solution? I do much appreciated.

---

<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:** [December 11, 2018, 10:03am UTC](https://discuss.elastic.co/t/how-to-get-the-terms-of-the-query-text-in-the-plugin-code/156433/2 "2018-12-11T10:03:29Z")

</div>

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