Indexing books with Elasticsearch: which pages contain hits? <p>I'm indexing books with Elasticsearch to search them with FTS. One of the requirements is that I have to display numbers of pages that contain hits.</p> <p>I initially planned to include page separators in indexed string, then get highlights when I search and count page separators before highlighted words. On a second thought, I'm concerned about performance issues. Some books may be up to 500 KB in size. Counting words in strings that long sounds like a <em>bad</em> idea. It would be much better to compare offsets of matched words with offsets of page separators. As I understand, <code>with_positions_offsets</code> causes ES to store these offsets, so ideally I'd like it to do the job for me.</p> <p><strong>Can this be done in ES? What are alternative solutions to finding on which page of a book a hit is?</strong></p>