Understanding Elasticsearch searching data flow

Search is a generic term for information retrieval. Elasticsearch provides various retrieval capabilities, including full-text searches, geo searches, range searches, scripted searches, and aggregations.

How does Elasticsearch execute a search query behind the scenes? The following diagram shows data flow for searching operations.

Elasticsearch Searching Data Flow

An algorithm for finding right-truncatable prime numbers

Inspired from my status on Facebook:

The prime number 73939133 is very special, if removing each digit from right to left of that number we get another prime numbers: 7393913, 739391, 73939, 7393, 739, 73 and 7.

One of my friends gave a challenge:

Can you write a program reading a number N from keyboard then finding the nearest prime number to N that satisfies the characteristics of 73939133?

As promised him, I would solve this challenge.