3
votes

As per my understanding, elasticsearch uses a structure called inverted index to provide full text search. It is clear that inverted index has terms and ids of the documents which has that term but the document can have any number of fields and the field name can be used in the query time to look/search only on that field. In that case how elasticsearch restricts/limits search only to a particular field? I would like to know if inverted index contains fields name or field id along with terms and document id.

Similar thing happens when you sort based on any field. So there could be a way to associate terms with field names. Please help me understand the intricacies involved here.

Thanks in advance.

2

2 Answers

3
votes

I would like to know if inverted index contains fields name or field id along with terms and document id.

Quoting from Lucene Docs

The same string in two different fields is considered a different term. Thus terms are represented as a pair of strings, the first naming the field, and the second naming text within the field.

In that case how elasticsearch restricts/limits search only to a particular field?

Each segment index maintains Term Vectors : For each field in each document, the term vector is stored. A term vector consists of term text and term frequency.

Hence, the indexes are maintained for each field in each document.

3
votes

We have a inverted index per field per index.

And there is something called field data cache ( or doc values ) which has the inverted "inverted index". All doc to field value lookup happens here.