elasticsearch logo

Search Indexing Strategies

Indexing data can be done on any database or specialized search framework. The example provided in this article uses Elasticsearch to index data.

Index by Date:

The index format for indexing by date can be date/type/id.

Examples: 2017-03-19/logs/1, web-2017-03-19/logs/1 and mobile-2017-03-19/logs/1 and so on.

Executing the requests from code: Elasticsearch

*Use appropriate date formatting.

C#: myrestapi.post(“http://localhost:9200/”+new System.DateTime() + “/logs/” + userid.ToString(), userjson)

Java: myrestapi.post(“http://localhost:9200/”+new java.util.Date() + “/logs/” + userid.ToString(), userjson)

You can retrieve all the user’s logs on a particular date using the query.

C#: myrestapi.get(“http://localhost:9200/”+new System.DateTime() + “/logs/_search”)

Java: myrestapi.get(“http://localhost:9200/”+new java.util.Date() + “/logs/_search”)

Shop the best electronics products at yoshop.com! Enjoy free shipping and up to 69% OFF! Shop now!

Index by Country/Region:

The index format for indexing by country can be country/type/id

Examples: usa/users/1, web-usa/users/1 and mobile-usa/users/1 and so on.

Index by Words:

The index format for indexing by words can be word/type/id

You can create as many indexes as the number of words in English dictionary. I hope you don’t need all of them.

Example: mail/links/1, search/links/1, google/links/1, facebook/links/1

Whenever a user enters the word facebook in the search box and clicks enter, you can go to the index facebook/links to retrieve your top results.

[CBC show=”y” country=”in”]

[/CBC]
[CBC show=”y” country=”us”]

[/CBC]

Index by Sentences (Search Engines):

Indexing by sentences can be done similar to index by words, however this is where things get complex. Each of you can have your own algorithm based on your needs to index by sentences. Google, Yahoo and Bing all have their own ways of indexing links based on sentences. We will go through one simple strategy

  1. Display the top few results from the indices with each word (word indices) in the sentence. User clicks on one of those links.
  2. Now create a new index with the whole sentence as index name and add the user clicked link to this index.
  3. Next time when the user enters a similar sentence in the search box and clicks enter then go get the results directly from the sentence index.
  4. If no sentence index exists then do step 1.
  5. Eventually you will build enough sentence indexes to cater the needs of your search.
  6. Initially the search might be slow as it keeps on creating sentence indexes, once there are enough sentence indexes your search will be blazing fast.