# Is it possible to fetch a document by term ID within a search/rescore plugin?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-fetch-a-document-by-term-id-within-a-search-rescore-plugin/195282>\
**Category:** Elasticsearch\
**Created:** [August 14, 2019, 11:21pm UTC](https://discuss.elastic.co/t/is-it-possible-to-fetch-a-document-by-term-id-within-a-search-rescore-plugin/195282 "2019-08-14T23:21:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zcharli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zcharli/32/52338_2.png) [@zcharli](https://discuss.elastic.co/u/zcharli)\
**Post date:** [August 14, 2019, 11:21pm UTC](https://discuss.elastic.co/t/is-it-possible-to-fetch-a-document-by-term-id-within-a-search-rescore-plugin/195282/1 "2019-08-14T23:21:57Z")

</div>

Hi, I have a concept that I'm thinking about implementing, but before I get my hands dirty, I would like to ask if this is possible. Advisory: Elasticsearch is new to me.

Suppose I have a index `cars` with document term ids as: `toyota_camry`, `honda_civic`, and `jeep_wrangler`. The document would contain attributes about that car.

Suppose I made a custom plugin that scores my cars/\_search results to rank cars that is more recommended for you. Suppose my `_search` query looks like this (I pass an `_id` to the plugin and expect the plugin to look it up):

```auto
{
  "query": {"terms":{ "_id": ["toyota_camry", "jeep_wrangler "]}},
  "rescore": {"my_plugin": {"car_key": "honda_civic"}}
}

```

Given that `honda_civic` is not part of the `query`, the honda is not found by the search query. From within the data nodes, can I some how fetch the document by id `honda_civic` and access it in my plugin? I want to be able to access the honda document, without having to provide it in or returned as a search result. The rescoring will be handled based on the user's `car_key`, the result would score the terms "toyota\_camry", "jeep\_wrangler " differently and may score toyota\_camry above jeep\_wrangler because the toyota is more like the honda.

If there is such a feature, is this inter-index look up considered fast/slow? This isn't really a join across multiple indexes.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 15, 2019, 7:27am UTC](https://discuss.elastic.co/t/is-it-possible-to-fetch-a-document-by-term-id-within-a-search-rescore-plugin/195282/2 "2019-08-15T07:27:40Z")

</div>

whenever you have to execute another query, I would consider it slow. You could probably implement that by writing your own `SearchPlugin` that implements a custom rescorer.

However, maybe something like [rank feature datatype](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/rank-feature.html) or [the vector datatype](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/dense-vector.html) could help you already a bit, allowing you to execute only one query.

---

<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:** [September 12, 2019, 7:36am UTC](https://discuss.elastic.co/t/is-it-possible-to-fetch-a-document-by-term-id-within-a-search-rescore-plugin/195282/3 "2019-09-12T07:36:59Z")

</div>

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