Elasticsearch uses a structure called an inverted index, which is designed to allow very fast full-text searches. An inverted index consists of a list of all the unique words that appear in any document, and for each word, a list of the documents in which it appears.
For example, let’s say we have two documents, each with a content field containing the following:
The quick brown fox jumped over the lazy dog
Quick brown foxes leap over lazy dogs in summer
To create an inverted index, we first split the content field of each document into separate words (which we call terms, or tokens), create a sorted list of all the unique terms, and then list in which document each term appears.
/api/createUse this to upload Json file and generate your index or indices for multiple file upload/api/searchUse this to search the created indices
- Clone this repository locally by opening your terminal and type
git clone https://github.com/cwizard2011/inverted-index-apiand press enter to clone this repo locally. - type "npm install" to install all the dependencies in your terminal.
- Create a ".env" file in the root directory of your repository and set
PORT = < port of your choice > - In your terminal, type
npm startto start the server - launch the postman and create a post request, using
localhost:(port)/api/create, in the body section, setkeytofilechooseFilein the option and upload your JSON files, clickSENDto create your indices. - To search for already created indices, using
localhost:(port)/api/search, in the body section, setkeytoterms, choosex-www-form-urlencodedand setvalueto the term you want to search for in the uploaded book.
NOTE: This API does not persist data, once you restart the server, the data get losts