Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch and NoSql database [duplicate]

Tags:

What is the use to use both ElasticSearch and a separated Nosql database ? Can't Elasticsearch be used both as a database and for search indexing ?

like image 908
rico Avatar asked Nov 06 '11 12:11

rico


People also ask

Is Elasticsearch NoSQL database?

Completely open source and built with Java, Elasticsearch is a NoSQL database. That means it stores data in an unstructured way and that you cannot use SQL to query it. This Elasticsearch tutorial could also be considered a NoSQL tutorial.

How do I stop Elasticsearch duplicates?

As you have seen in this blog post, it is possible to prevent duplicates in Elasticsearch by specifying a document identifier externally prior to indexing data into Elasticsearch. The type and structure of the identifier can have a significant impact on indexing performance.

How is Elasticsearch similar to MongoDB?

Both Elasticsearch and MongoDB support document-based data models but can also support traditional relational data represented by rows and columns. Elasticsearch has two ways of dealing with relational data: a nested document model and a parent-child document model.

Which process avoid duplication of data in the database?

You can prevent data duplicates in a database by creating a unique index. The unique index will demand that each data in the indexed field is unique in value and properties. You can create a new index by setting up a data-definition query that creates a new index. This can be done using SQL view.


1 Answers

Yes, you can use ElasticSearch as a data source as well as an index.

By default each document you send to the ElasticSearch system is index, and, the original document is stored as well. This means whenever you query ElasticSearch you can also retrieve the original JSON document that you indexed.

If you have large documents and you want to be able to retrieve a smaller amount of data then when you can use the mapping API to set "store" to "yes" for specific fields, and then use the "fields" key to pull out specific fields you might want.

In my system I have address autocompletion and I only fetch the address field of a property. Here is an example from my system:

_search?q=FullAddress:main&fields:FullAddress

Then when a user selects the address I pull up the entire JSON document (along with others).

Note:

  1. You cannot do updates like you can in SQL (update all items matching a query to increase an attribute, let's say)
  2. You can, however, add a new document and replace the existing one at the ID you want to update. Elastic search increments a _version property on each document which can be used by the developer to enforce optimistic concurrency, but it does not maintain a separate version history of each document. You can only retrieve the latest version of a document.
like image 80
David Kullmann Avatar answered Nov 23 '22 02:11

David Kullmann