Specify the elastics search index in the payload

My request

I am writing an Elasticsearch request and specifying the requested indexin the URL and the request in an external JSON file:

curl

curl -s \
     -u $user:$pass \
     https://example.com:9243/index_name/search 
     -d @query.json

query.json

{
  "size": 5,
  "from": 0,
  "sort": [
    {
      "@timestamp": {
        "order": "desc",
        "unmapped_type": "boolean"
      }
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "source:*.log",
            "analyze_wildcard": true
          }
        }
      ]
    }
  },
  "_source": {
      "include": ["message", "@timestamp"],
      "exclude": "_*"
  }
}

My problem

I would like to specify the index name in the query file, not the URL.

What i tried

My question

What is the correct way to specify an index in

+4
source share
1 answer

Look at the index request , there you will see that you can set the index inside the json request.

If you have any problems let me know.

0
source

Source: https://habr.com/ru/post/1687114/


All Articles