What's the different between index and update document in elasticsearch? - elasticsearch

As we know when we update an existed document the Elasticsearch engine will reindex the document and mark the previous document deleted. But for the restful API, it's same. So I guess the ElasticSearch will analysis the document whether exist by the unique document ID and then update or index.
So my question is, we don't need to care the index or update functionality, because both restful API and Java Client are PUT the same endpoint, Am I right?

The most difference for PUT and POST document in Elasticsearch:
POST will create a new document with a new unique ID.
PUT will update the current document without change ID.
so if your ID is important to you like for some context, you should use PUT to update a document to keep this ID.

Related

Updating fields of a Couchbase document if it exists by Go

I am using gocb library. I want to update specific field of a document.
However if the document does not exist, I don't want to do anything I will just produce an error message.
You can say that first retrieve the full document itself and make update and then insert it.It is possible right. But I want to use a ready for use method for this purpose if there is any. Since I don't want to retrieve the document. I just want to update some fields of it.
Is there a way for this in gocb library?
If you want to update parts of the document, you can look at sub-document operations. It only transmits the accessed sections of the document over the network making it more efficient for small changes.
Example: https://couchbase.live/examples/basic-go-subdoc-mutate
If you want to rewrite the entire document, you are looking for Replace() which replaces an existing document with a new one. It is similar to Upsert() except that it can only replace existing documents & not create new ones.
General Reference:https://docs.couchbase.com/server/current/guides/updating-data.html

ElasticSearch Updating Document

General help question, but I wanted to ask a clarifying question on how updating documents in ES works.
When adding a document request to the elasticsearch indexing, do we have to include all fields for that document or just the ones I want to update?
If there already exists a document with the same document id, would our new document request override all data in that document or just update the fields listed in this document request? In other words, do I need to supply all the fields in this document request or just the ones I want to update? Thanks!
The docs:
The update API also supports passing a partial document, which is
merged into the existing document.

Elasticsearch: How to add "created_at" and "updated_at" timestamps?

I have a database where I should store created_at and updated_at fields for each document.
The created_at field should be created once on first document insert.
The updated_at field should be created on first document insert and should be updated via Bulk API on each update, even if none of the document fields are changed.
The question is: how to add those timestamps?
I believe that Elasticsearch used to have a feature to add these automatically, but it was removed in later versions to improve performance. You would have to add these fields to your mapping and then implement a process to set those fields. One way to do this is with an ingest pipeline, which someone explains in the ES forum. You will want to check the docs for how to implement pipelines with your particular version of Elasticsearch.
Suggestion: You should always check the forums for Elasticsearch questions. The community seems to be more active on there, and devs will also often respond to questions.

How does one return results from the google search appliance based on entity names?

My app needs to GET results from the GSA based on entity name, is this possible? I can retrieve results based on metadata using requiredfields but I cannot seem to find any documentation on how to retrieve results based on entity names (entity name:entity value pairs). Using the indexing diagnostics on the the GSA I can see that the GSA is tagging the appropriate docs with the correct entity name: entity value pairs.
Entities are pushed as metadata, but their are prefixed with "gsaentity_", so it's really working the same way as metadata. The prefix is just there to avoid colliding with your existing metadata.
For instance, let's pick the default "Date" entity preloaded in the box. If you wanted to use it, you should do :
&requiredfields=gsaentity_Date:value

Necessary to validate _id in Meteor collections?

I'm using Collection.allow(options.insert) to validate the documents the users inserts into the collection. What I wonder is which validation tests I need to use on the _id property of the inserted doc (I use random strings as id, not the Mongo-style objectId).
Do I need to check that _id is a string looking like an id, or does the database refuse the document if the _id property is invalid? Should I also make sure that no other document in the database has that id?
Strictly speaking you do not need to do any validation tests of the _id. The database will refuse the insert if the _id you give is not unique but I think that is the only rule. Checking that the _id is unique could also be picked up afterwards if the insert errors.
Other checks are optional and are just to allow users to access, insert, or remove the documents you want them to.

Resources