0

I'am tring to store the results of my search request in new index. This is my code:

POST /_reindex
{ 
  "source": {
    "index": "my_index_name",
    "query": {
    "bool": {
      "must": [
        {
          "match": {
            "host.hostname": "value_1"
          }
        },
        {
          "match": {
            "message": "value_a"
          }
        }
      ]
    }
  },
   "size":3
  },
  "dest": {
    "index": "new_test"
  }
}

This request is limited to a size of 3. However the size limit is not taken into account. Hence the Post request result is 502 error with this message:

{"ok":false,"message":"backend closed connection"}

My question is how can i store the result of the request above in a new index in ELasticsearch? Thank you in advance for your help.

saad
  • 11
  • 3

2 Answers2

0

You need to specify the top-level max_docs parameter instead of source.size:

POST /_reindex
{
  "max_docs": 3,
  "source": {
    "index": "my_index_name",
    "query": {
      "bool": {
        "must": [
          {
            "match": {
              "host.hostname": "value_1"
            }
          },
          {
            "match": {
              "message": "value_a"
            }
          }
        ]
      }
    }
  },
  "dest": {
    "index": "new_test"
  }
}
Val
  • 207,596
  • 13
  • 358
  • 360
  • You are faster then lightning !! I didnt refresh page so not aware that you have already posted answer. SO should implement functionality to show popup or notification when someone writing answer on question similar to what discuss.elastic have. – Sagar Patel May 05 '22 at 10:51
  • HAHA you made my day Glad to help – Val May 05 '22 at 10:53
0

You need to set max_docs param to your request.

POST _reindex
{
  "max_docs": 1,
  "source": {
    "index": "my-index-000001"
  },
  "dest": {
    "index": "my-new-index-000001"
  }
}

size param is for number of documents to index per batch.

By default _reindex uses scroll batches of 1000. You can change the batch size with the size field in the source element

Sagar Patel
  • 4,993
  • 1
  • 8
  • 19