Elasticsearch - 6.5.1
Nest - 6.5.1
Hi All,
I am able to write code to update the single document 1 at a time.
var scriptParams = new Dictionary<string, object>
{
{"id", BaseMapping.id}
};
return Client.UpdateByQuery<BaseMapping>(s => s
.Query(q => q
.Match(m => m
.Field(f => f.question_id.Suffix("raw"))
.Query(BaseMapping.id.ToString())
)
)
.Script(script =>
script.Source((
$"ctx._source.id=params.id;" +
$"ctx._source.answer='" + BaseMapping.answer + "';" +
$"ctx._source.question='" + BaseMapping.question + "';"
)
)
.Params(scriptParams)
)
.Conflicts(Elasticsearch.Net.Conflicts.Proceed)
);
I wanted to write code which can do a bulk update with below logic
1-check if the document exists based on _id then update the existing document and if it doesn't exist then insert the document.
I have referred one code from the elasticsearch documentation.
POST twitter/_update_by_query
{
"script": {
"source": "if (ctx._source.tags.contains(params.tag)) { ctx.op = 'update' } else { ctx.op = 'insert' }",
"lang": "painless"
},
"query": {
"term": {
"user": "kimchy"
}
}
}
can anybody help me with how to write it in Nest bulk update.?