ElasticSearch — Inverted Index, Source, Index, Norms, Routing…

Photo by Ryan Geller on Unsplash

Lucene vs ElasticSearch

Differences between Lucene and ElasticSearch:

  • ElasticSearch is built over Lucene and provides a JSON based REST API to refer to Lucene features.
  • Elasticsearch provides a distributed system (which is something Lucene is not capable of) on top of Lucene.
  • Elasticsearch provides other supporting features like monitoring and management APIs.

What is Inverted Index?

Sample documents and resulting inverted index — elastic.co

What are _source and source?

When you index a document in Elasticsearch, the original document (without any analyzing or tokenizing) is stored in a special field called _source.

{
"_source" : {
"enabled" : false
},
"properties": {
"organizationId": {
"type": "keyword"
},
"accountId": {
"type": "keyword"
},
"type": {
"type": "text",
"analyzer": "whitespace"
}
}
}
"_source": [ "field1.*", "field2.*" ],
  • it is declared in field “_source” (like “_source”: [ “field1.*”, “field2.*” ] example)
  • you disabled it by setting “_source” : { “enabled” : false },” but set this field’s “store” option as “true”

What is index?

For a field to be searchable, mapping option “index” should be set to “true” which is also the default value and means it is indexed and analyzed by default.

{   
"foo": {
"type": "text",
"index": true
}
}
{   
"foo": {
"type": "keyword",
"index": true
}
}

What is norms?

Norms store various normalization factors (numbers to represent the relative field length and the index time boost setting) that are later used at query time in order to compute the score of a document relatively to a query.

"properties": {
"title": {
"type": "text",
"norms": false
}
}

Nodes & Shards

  • An Elasticsearch node contains shards.
  • A single Elasticsearch index is spread across nodes using shards.
  • Each shard holds a partition of the documents in the Elasticsearch index.
  • Each one of these shards is an instance of Lucene.

What is routing?

Elasticsearch can store copies of an index’s data across multiple shards on multiple nodes. When running a search request, Elasticsearch selects a node containing a copy of the index’s data and forwards the search request to that node’s shards. This process is known as search shard routing or routing.

{
"_routing": {
"required": true
},
"properties": {
"organizationId": {
"type": "keyword"
},
"accountId": {
"type": "keyword"
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nil Seri

Nil Seri

I would love to change the world, but they won’t give me the source code | coding 👩🏼‍💻 | coffee ☕️ | jazz 🎷 | anime 🐲 | books 📚 | drawing 🎨