# \_id extraction performance in plugin

**URL:** <https://discuss.elastic.co/t/id-extraction-performance-in-plugin/172483>\
**Category:** Elasticsearch\
**Created:** [March 15, 2019, 8:34am UTC](https://discuss.elastic.co/t/id-extraction-performance-in-plugin/172483 "2019-03-15T08:34:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vgindin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vgindin/32/42012_2.png) [@vgindin](https://discuss.elastic.co/u/vgindin)\
**Post date:** [March 15, 2019, 8:34am UTC](https://discuss.elastic.co/t/id-extraction-performance-in-plugin/172483/1 "2019-03-15T08:34:08Z")

</div>

Hello all!

We use machine learning to score products from an index in our custom elasticsearch search plugin. For this scoring purpose, I need to fetch additional data from external db using product ids, founded by textual matching in a plugin.

We use product id as elasticsearch \_id of a document. So we can fetch a product by GET query.

Performance question: what is the most effective way to fetch product id inside the Weight?  
Assume we have 20000 matched products.

1. \_id is a stored field and I can use _org.elasticsearch.index.fieldvisitor.FieldsVisitor_ object to extract product id like this (Like it happen in _org.elasticsearch.search.fetch.FetchPhase_):  
FieldVisitor fv = new FieldVisitor(false);  
fv.reset();  
fv.postProcess(queryContext.getQueryShardContext().getMapperService());  
reader.document(doc, fv);  
productId = fv.uid().id();  
This case will work more than 1second for 20000 products
2. If we hold product id as a separate DocValue field and fetch it in usual way.  
It will work about 400ms for 20000 products.

The case 2 is faster, but it is also too long. Could you advise me the fastest way?

Regards,  
Vadim Gindin

---

<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 12, 2019, 8:34am UTC](https://discuss.elastic.co/t/id-extraction-performance-in-plugin/172483/2 "2019-04-12T08:34:11Z")

</div>

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