Questions

Pablo Reyes Tapia
6 min readDec 1, 2020

Assignment

How does elasticsearch store the index in disk?

This was my experience to know how elasticsearch indexes are stored. To comment on the environment in which I decided to do the tests, I used a system based on the linux architecture, to be more specific I used the Debian distribution.

The data, or documents, are kept in indexes. It could be assimilated as a record in a relational database. Where each of these records will be saved in JSON format. Previously each one could be saved with a “type” having a similarity with the concept of tables, although this has become obsolete, it is possible to continue using this “type” field for the purpose of a better reading of what we are indexing.

What is an index in elasticsearch? An index is a set of documents with similar characteristics. The way elasticsearch works is through inverted indexes.

As I mentioned all data is known in elasticsearch as a document, but how does it store documents in reverse links?

We usually know a direct index that points, in this case, to the entire document, for example:

to review the contained data you would have to stop at the index and review the entire chain

Using the inverted index:

Now you can parse word by word until you find a match just in which document it is. For me it is similar to a box of marbles with different types of holes, where certain marbles will fall into a certain position depending on their size in the order in which you throw them and you do not have to build specific paths for each sequence of marbles. When you finish dropping all of them you will be able to see the sequence that has been formed and all the indexes in which this document is located. Which could help to establish relationships with other possible answers such as correctors or search boxes when we do not know the exact term, but we write some patterns that may have a match.

The nodes are an important part since they participate in the indexing and search tasks. These are where the documents are stored. They can be configured in the file elasticsearch.yml::

In order to create new indices and interact with elastic we have two ways:

1.- By command line:

Where we can see that we have our first index created under the name of my-index-000001, a _doc type where now all the documents go to the same type. The index in automatic will generate two shards by default.

2.- Using the Kibana DevTools tool:

We can create a new index or create it at the same time we enter a new record.

In the cases where we store text strings for example for searches, the sentences are stored in tokens, not in sentences as such. Special characters, accents, capital letters, plurals are removed and verbs are used in their normal form.

This is achieved by making use of index parsers in order to further simplify the search.. Example in another text string we can:

*Remove lowercase

*Remove accents

*Get tokens (keywords)

*Delete stopwords: of, the, a, our

- What is the structure of a servlet in Java? (primary stack)

A servlet is a java class that is run on the server side. And this allows us to accept requests made by a client from a web browser. We can create this Class inheriting from HttpServlet class.

When structuring a Servlet class we can commonly use two methods:

doGet receives requests through the GET method from the client

doPost receives requests, but as long as they come with the POST method.

I had had little experience using servlets, but what I immediately remembered is that from our front end we receive values that we send to our server depending on the operation we want to perform.

These in turn have two parameters with which they will be allowed to perform internal operations with the data that comes from the client side. These are the request and the response.

request: contains all the information from the client side. Imagine that you want to access an account on facebook, instagram, etc. This request will bring all those data such as username, password or email. This applies to both doPost and doGet methods.

response: This is the response made by the server or in this case the servlet towards the view. As in the previous example, after having sent all the data about a Facebook user to log in, then in the expected response from the client, you can access your account and see all the data corresponding to your user shown on the screen.

In the example you use, you can see an object of type PrintWriter. This is an output that will allow us to send content to the browser. They can be from plain text, HTML or executable strings.

  • How is match object used in React? (secondary stack)

What I understood is that a match object can contain information from a specific route or even from the current route of the browser, thus allowing us to create dynamic routes, transfer properties between components like values. For example de User ID from one component to another.

To be able to explain it better I found the following example where a value is passed through a URL.

First of all in our routes.js file we define the following route

Let’s say we want to be redirected to that new UserIdContainer component from a link. From a list where we have all the user photos, we define the following.

Inside the following function we define the property “to” in UserCard

As a next step, we structure our “to” property to be able to assign it to our link

we create our new component which will receive the address

using match.params.userIndex we are retrieving the value that we were previously sending from the path / user-info /: userIndex that we established in routes.js.

How do you create a match object?

To talk about creating the match object it is necessary to talk about the <Route> component of the React-router library. <Route> has 3 methods:

  • <Path component>
  • <Route processing>
  • <Children route>

When using any of the route components, they will already have the following properties:

  • match
  • Location
  • history

How does React know what component should show by using an url?

In the example I talked about the routes.js file. This file is where all our pages are stored, which react takes them as new components.

In this case our new page or component called UserIdContainer was declared in our routes.js file. Inside there is the <CardContent> element that shows the user’s name and is also a link, but it could not access this component or show it in this case if it was not previously registered in router.js. By clicking on the <CardContent> element, you access the path directory and that is where you are allowed to show a new component with the URL that is registered. And as mentioned, the handling of properties is allowed even the creation of a dynamic URL since it can take any value that corresponds to userIndex.

--

--