Imagine a class as:
class DummyClass
{
String field1;
String field2;
}
I'm able to create an DummyClass
object and save it on ES:
DummyClass dummy = new DummyClass();
dummy.field1 = "sample1";
dummy.field2 = "sample2";
byte[] source = this.jacksonMapper.writeValueAsBytes(dummy);
this.elasticsearchResources.getElasticsearchClient()
.prepareIndex()
.setIndex("index")
.setType("type")
.setSource(source)
.request();
source
's content is:
{
"field1": "sample1",
"field2": "sample2"
}
So, I need to do a change like: dummy.field1 = null
, so I need field1
is deleted (I don't want ES set field1 = null
).
So, I've tried this:
dummy.field1 = null;
byte[] source = this.jacksonMapper.writeValueAsBytes(dummy);
this.elasticsearchResources.getElasticsearchClient()
.prepareUpdate()
.setIndex("index")
.setType(type)
.setId(id.toString())
.setDoc(source)
.setUpsert(source)
.setDetectNoop(true)
.request();
source
's content is:
{
"field2": "sample2"
}
After that, ES doesn't delete field1
from document.
I'm not quite able to figure out what I'm doing wrong.