Change multiple fields with different variable

Hi,
I am using version -> elasticsearch-7.5.2
I want to change multiple fields for a specific index.
each field should get a different value.
I am using c#
Is it possible?

currently, it changes all the fields for the same variable.

This is my code:
UpdateByQueryResponse task = ElasticClient.UpdateByQuery(u => u.Index("test")
.Query(q => q
.MatchAll()
).Script(d => d
.Source("ctx._source.wcf += 1;").Lang("painless"));

Thanks.

1 Like

Hi,
Does anyone knows the answer?
Is the questions clear enough?

Welcome!

Some information before answering:

It can take time to get an answer

Please be patient in waiting for responses to your question and refrain from pinging multiple times asking for a response or opening multiple topics for the same question. This is a community forum, it may take time for someone to reply to your question. For more information please refer to the Community Code of Conduct specifically the section "Be patient". Also, please refrain from pinging folks directly, this is a forum and anyone that participates might be able to assist you.

If you are in need of a service with an SLA that covers response times for questions then you may want to consider talking to us about a subscription.

It's fine to answer on your own thread after 2 or 3 days (not including weekends) if you don't have an answer.

Code formatting

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.

Your question

Is that something you want to do constantly? What is the use case for this?
Do you have a JSON example of a document you'd like to modify? And a typical JSON document of what it should look like at the end?

Hi,
Thanks for the fast response.

Is that something you want to do constantly?
-This is something I'd like to do under specific circumstances when I need to number my documents in a specific manner.

What is the use case for this?
-Numbering documents according to this field.

Do you have a JSON example of a document you'd like to modify? And a typical JSON document of what it should look like at the end?

Before:

    {
    "_index": "test",
    "_type": "_doc",
    "_id": "aaaa",
    "_version": 1,
    "_score": 1,
    "_source": {
    "wcf": ""
    }

{
"_index": "test",
"_type": "_doc",
"_id": "bbbb",
"_version": 1,
"_score": 1,
"_source": {
"wcf": ""
}

 

After we run the updateByQuery (note the WCF field has changed):

{
"_index": "test",
"_type": "_doc",
"_id": "aaaa",
"_version": 1,
"_score": 1,
"_source": {
"wcf": "1"
}


{
"_index": "test",
"_type": "_doc",
"_id": "bbbb",
"_version": 1,
"_score": 1,
"_source": {
"wcf": "2"
}

Currently, I am able to change the WCF field but for the same value to all the documents.

Thanks.

I think you did not read the "Code formatting" part of my answer. Please update your post.
Also in your examples please remove all non needed fields. That will help to focus on the actual problem.

Hi,
Thanks for the fast response.

Is that something you want to do constantly?
-This is something I'd like to do under specific circumstances when I need to number my documents in a specific manner.

What is the use case for this?
-Numbering documents according to this field.

Do you have a JSON example of a document you'd like to modify? And a typical JSON document of what it should look like at the end?

Before:

    {
    "_index": "test",
    "_type": "_doc",
    "_id": "aaaa",
    "_version": 1,
    "_score": 1,
    "_source": {
    "wcf": ""
    }

{
"_index": "test",
"_type": "_doc",
"_id": "bbbb",
"_version": 1,
"_score": 1,
"_source": {
"wcf": ""
}

 

After we run the updateByQuery (note the WCF field has changed):

{
"_index": "test",
"_type": "_doc",
"_id": "aaaa",
"_version": 1,
"_score": 1,
"_source": {
"wcf": "1"
}


{
"_index": "test",
"_type": "_doc",
"_id": "bbbb",
"_version": 1,
"_score": 1,
"_source": {
"wcf": "2"
}

Currently, I am able to change the WCF field but for the same value to all the documents.

Thanks.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.