Sajeesh Krishnan
Sajeesh Krishnan

Reputation: 93

Elastic-search query failing to run

I'm pretty new to elastic search and would like to write a query for all of the values a specific field when it matches a condition, I tried building the below query, basically its from Kibana, i copied the request body and tried running with ES node.

curl -XGET "http://localhost:9200/test_index/_search?pretty" -H 'Content-Type: application/json' -d'
 {
  "version": true,
  "size": 500,
  "sort": [
    {
      "actual_start": {
        "order": "desc",
        "unmapped_type": "boolean"
      }
    }
  ],
  "_source": {
    "excludes": []
  },
  "aggs": {
    "2": {
      "date_histogram": {
        "field": "actual_start",
        "interval": "5m",
        "time_zone": "Asia/Kolkata",
        "min_doc_count": 1
      }
    }
  },
  "stored_fields": [
    "*"
  ],
  "script_fields": {},
  "docvalue_fields": [
    {
      "field": "Updated",
      "format": "date_time"
    },
    {
      "field": "actual_end",
      "format": "date_time"
    },
    {
      "field": "actual_start",
      "format": "date_time"
    },
    {
      "field": "created_on",
      "format": "date_time"
    },
    {
      "field": "planned_start",
      "format": "date_time"
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        },
        {
          "exists": {
            "field": "Number"
          }
        },
        {
          "match_phrase": {
            "change_manager_group": {
              "query": "Change Managers - 2"
            }
          }
        },
        {
          "range": {
            "actual_start": {
              "gte": 1556028682454,
              "lte": 1556043082454,
              "format": "epoch_millis"
            }
          }
        }
      ],
      "filter": [],
      "should": [],
      "must_not": []
    }
  }'

I am getting the below error, I believe this is related to formatting the query

{
  "error" : {
    "root_cause" : [
      {
        "type" : "json_e_o_f_exception",
        "reason" : "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@177d880d; line: 2, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@177d880d; line: 85, column: 1448]"
      }
    ],
    "type" : "json_e_o_f_exception",
    "reason" : "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@177d880d; line: 2, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@177d880d; line: 85, column: 1448]"
  },
  "status" : 500
}

What i am doing wrong here?

Upvotes: 0

Views: 469

Answers (1)

Erez Ben Harush
Erez Ben Harush

Reputation: 867

Elastic search is complaining about a missing curly brace at the end of your json string. You can verify your json schema using any of the many (oh so many) online json validators like https://jsonlint.com/

Upvotes: 1

Related Questions