1

This is the request body that I for this endpoint using Postman localhost:9201/response_v2_862875ee3a88a6d09c95bdbda029ce2b/_search

{ "_source": ["_id"], "from": 1, "size": 10, : { "should": { "match": { } }, { "range": { "_updated_at": { "from": "36163", "include_lower": true, "include_upper": true, "to": null } } }] } } } 

To this url localhost:9201/rensedbda029ce2b/_search

And I get the results https://gist.gith

But when I make the same request from my server to ES I get an error saying "elastic: Error 400 (Bad Request): Expected [START_OBJECT] but found [START_ARRAY] [type=parsing_exception]"

These are some snippets of my code. I get the query from another util function and use that while making the call to ES.

This is the call to ES res, err = r.esConn.Search(indexName).e(requestBody.ResponsePageLength).Do(ctx)

and the query builder function is this, it takes arguments which are extracted from the body of the request to my server and builds a query based on that.

func CreateMonitoringPipeline(maxResponseTime string, responseQueries []ResponseQuery, baselineFormId string) *elastic.BoolQuery { finalQuery := elastic.NewBoolQuery() dateRangeMatchQuery := elastic.NewRangeQuery("_updated_at"). Gte(maxResponseTime) finalQuery.Filter(dateRangeMatchQuery) } return finalQuery } 

I can't figure out why is this happening? my ES is running using the ES binary and my server runs in a docker container.

Completely new to ES and golang so please help.

UPDATE:

This is what I got when I logged my request using SetTraceLog

| ELASTICPOST /resp8ecf8427e/_search HTTP/1.1 | Host: 172.17.0.1:9201 | User-Agent: elastic/5.0.81 (linux-amd64) | Transfer-Encoding: chunked | Accept: application/json | Content-Type: application/json | Accept-Encoding: gzip | | 7 | ["_id"] | 0 

I can't understand what do the 7 and ["_id"] mean. Is this my request body that ES received?

4
  • I'm not sure if there are other errors but I think you intended monitoringAnswersPipeline = append(monitoringAnswersPipeline, esSubQuery) to go inside the for loop, otherwise it just adds the final esSubQuery rather than all of them. Commented Jun 15, 2019 at 17:52
  • Also, if you are using the olivere/elastic library which I think you are you can turn on a feature to print the request before it is sent by doing calling SetTraceLog when you create the client. godoc.org/github.com/olivere/elastic#SetTraceLog This will print out the actual request you are making so you can compare it with the one you are sending in Postman Commented Jun 15, 2019 at 17:55
  • @IainDuncan I have added the ES logs to my question, can you take a look please? Commented Jun 16, 2019 at 14:05
  • thanks! That had enough information in it to provide an answer, hope this helps. Commented Jun 16, 2019 at 17:33

1 Answer 1

1

Thanks for uploading the logs, you are right that the ["_id"] is the request being sent. The problem is in the request line as Source([]string{"_id"}) does not set the source field to ["_id"] as you intended but instead:

Source allows the user to set the request body manually without using any of the structs and interfaces in Elastic.

https://godoc.org/github.com/olivere/elastic#SearchService.Source

You want to use FetchSourceContext instead:

res, err = r.esConn.Search(indexName).From(requestBody.MaxResponseTimestampCount).FetchSourceContext(elastic.NewFetchSourceContect(true). Include("_id")).Query(query).Size(requestBody.ResponsePageLength).Do(ctx) 

https://godoc.org/github.com/olivere/elastic#SearchService.FetchSourceContext

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.