Hello Folks,
i am looking for a good Tutorial about GetRequest ,GetResponse and check Exists Field in JSON Data . I am using Elasticsearch 6.3.1 and Java 8.0 , i found this Page about Request and Response in Elasticsearch 6.0 , and some Functions are not compatible.
Why is that?
And How can i improve it to check an existing Json Data in Elasticsearch ,
to avoid sending the same Data twice into Elastic???
I am using REST ClientAPI Java to creat Index in Elasticsearch and feed it with Json Data ,
those Data should not be similar, therefore i am asking for help , any Idea to check the Data bevor sending??
And How can i improve it to check an existing Json Data in Elasticsearch ,
to avoid sending the same Data twice into Elastic???
Well. What is the problem of sending it multiple times? As long as you are using the same id, the last call will just overwrite the existing one.
Not sure it is worth checking for every single call if the document already exist or not. You probably need to fix something in your application instead IMO.
Anyway, you can also use the Create API instead of Index API. That way if the document already exists the operation will just fail. See Index API | Java REST Client [7.17] | Elastic
thx for Response ,
i need to check a specific field inside a JSON Data , so i can compare if other Data has the same field.
Like example , if i have two diffierent " Index id's " for two similar Data with the similar fields , this Case i want to avoid , the Question is how ?? And how to check if the similar Data in wich "id " exists?? overwriting in this Case is not helpfull.
Is the Elasticsearch Version 6.3.1 not compatible enough to handle this Case??
To solve this, I'd probably generate an id which is a fingerprint of whatever content you want. So if 2 documents are similar (ie they are sharing the same fingerprint), you won't be able to index duplicates.
Is the Elasticsearch Version 6.3.1 not compatible enough to handle this Case??
The HL client 6.3.1 is probably not enough advanced but the 6.8.0 client might be useable with Elasticsearch Server 6.3.1. You need to test it.
Anyway, I'd recommend upgrading the server as well to 6.8.
Here is what I'd write with a 7.2.0 client (pretty similar with the 6.8.0 client):
thx for Response , i wrote a similar Code like yours, how can i get a specific Field from JSON Index, like follow , i have this example in Elasticsearch, after this Example i wrote a Request and Respons Index in order to get the "application_id": 6 field , but it did not print the "application_id": 6 on my Console , can you please check my Code down , am i missing anything?
am i using the source in the right why , give it the fieldname i want to look for and the value in that field??
The Java example you shared is different than the JSON one (BTW please indent your code to make it readable).
In Java, you are writing a document like:
{
"application_id":"6"
}
In Java, you are writing a document like:
{
"application_id":"6"
}
The Json version is:
{
"entity": {
"application_id": 6
}
}
Not the same field name application_id vs entity.application_id, not the same format number vs string... So probably not the same mapping.
About you Java code unless you have only one primary shard, the code is not going to work and probably to compile.
You are calling index method with a GetRequest. I doubt this can work.
thx for Advice , i modified the Code like below , but it updated the all JSON DATA and wrote inside the source just the "application_id": 6, so now my source is completely changed, that is not what i actually wanted, i just want to get the field "application_id": 6 from the JSON Index and print it to my Console.
Here what i got from the below Code,
Please any last Suggestion to hold just the field "application_id": 6 from my JSON Data and print it to my Console without changing the Original JSON Data in Elasticsearch??
thx.
yes the Output should just be the field "application_id": 6 from my JSON Data , printed to my Console. without chaning or updating the Original JSON Data in Elastic .
it print me the result with value 10000 , and change(update) my already exists Original JSON DATA in Elasticsearch. That what i wanted to avoid.
It seems "IndexRequest" did not hold the Field from my Original JSON DATA , it just overwrite it.
thx.
That's true. It's "updating" the whole document. Actually it is a Delete and an Index all together.
If your question was "how can I do partial updates of a document?" then have a look at Update API | Elasticsearch Guide [8.11] | Elastic
TBH I don't really like this API and found it useful if and only if you have very big documents to update like 100's of kb of JSON. In that unique moment it makes sense to me to avoid sending too much data on the network.
For smaller documents, then I always prefer sending the whole document again.
An Update API is basically doing:
GET the existing document
Merge it with what you sent within the Update Request
is there no Hold API from JSON Data without Updating or Deleting the existing Data?? Just hold the JSON DAta or a specific Part or Field from it , without doing anything else??
Cause i do not want to Update or change existing Data.
thx.
So I have absolutely no idea about what you want to do.
Could you share a full example, pure JSON based without any Java code and explain the result you are getting today and what do you want to get instead?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.