Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search call fails with message: 'Unable to parse/serialize body' #22

Closed
wires opened this issue Jan 8, 2014 · 8 comments
Closed

Search call fails with message: 'Unable to parse/serialize body' #22

wires opened this issue Jan 8, 2014 · 8 comments

Comments

@wires
Copy link

wires commented Jan 8, 2014

When executing a query I get the mentioned message. Here is some example code:

var es = require('elasticsearch');
var c = new es.Client({log: 'trace'});

// log r with text s
var ok = function(r) { console.log('succes', r); }
var fail = function(r) { console.log('failed', r); }

// ok this shit works
c.search({
    index: 'places',
    q: 'pants'
}).then(ok, fail);

// fails: message: 'Unable to parse/serialize body'
c.search({
  index: 'places',
  type: 'snackbar',
  body: {
    query: {
      match: {
        heading: 'het'
      }
    }
  }
}).then(ok, fail);

// fails, same.
c.search({
    index: 'places',
    body: { query: { match_all: {} } }
}).then(ok, fail);

This is the result of running it:

node bug.js
Elasticsearch INFO: 2014-01-08T18:48:32Z
  Adding connection to http://localhost:9200/

Elasticsearch DEBUG: 2014-01-08T18:48:32Z
  starting request { method: 'POST',
    path: '/places/_search',
    query: { q: 'pants' } }


Elasticsearch DEBUG: 2014-01-08T18:48:32Z
  starting request { method: 'POST',
    path: '/places/snackbar/_search',
    body: { query: { match: [Object] } },
    query: {} }


Elasticsearch DEBUG: 2014-01-08T18:48:32Z
  starting request { method: 'POST',
    path: '/places/_search',
    body: { query: { match_all: {} } },
    query: {} }


Elasticsearch TRACE: 2014-01-08T18:48:32Z
  curl 'http://localhost:9200/places/_search?q=pants&pretty=true' -XPOST
  <- 200
  {
    "took": 1,
    "timed_out": false,
    "_shards": {
      "total": 3,
      "successful": 3,
      "failed": 0
    },
    "hits": {
      "total": 0,
      "max_score": null,
      "hits": []
    }
  }

Elasticsearch INFO: 2014-01-08T18:48:32Z
  Request complete

succes { body:
   { took: 1,
     timed_out: false,
     _shards: { total: 3, successful: 3, failed: 0 },
     hits: { total: 0, max_score: null, hits: [] } },
  status: 200 }
Elasticsearch TRACE: 2014-01-08T18:48:32Z
  curl 'http://localhost:9200/places/_search?pretty=true' -XPOST -d '{
    "query": {
      "match_all": {}
    }
  }'
  <- 200
  {"took":1,"timed_out":false,"_shards":{"total":3,"successful":3,"failed":0},"hits":{"total":1,"max_score":1.0,"hits":[{"_index":"places","_type":"snackbar","_id":"1","_score":1.0, "_source" : {heading:"Het Geveltje", text: "Foo"}}]}}

Elasticsearch INFO: 2014-01-08T18:48:32Z
  Request complete

failed { message: 'Unable to parse/serialize body',
  body: '{"took":1,"timed_out":false,"_shards":{"total":3,"successful":3,"failed":0},"hits":{"total":1,"max_score":1.0,"hits":[{"_index":"places","_type":"snackbar","_id":"1","_score":1.0, "_source" : {heading:"Het Geveltje", text: "Foo"}}]}}',
  status: 200 }
Elasticsearch TRACE: 2014-01-08T18:48:32Z
  curl 'http://localhost:9200/places/snackbar/_search?pretty=true' -XPOST -d '{
    "query": {
      "match": {
        "heading": "het"
      }
    }
  }'
  <- 200
  {"took":2,"timed_out":false,"_shards":{"total":3,"successful":3,"failed":0},"hits":{"total":1,"max_score":0.19178301,"hits":[{"_index":"places","_type":"snackbar","_id":"1","_score":0.19178301, "_source" : {heading:"Het Geveltje", text: "Foo"}}]}}

Elasticsearch INFO: 2014-01-08T18:48:32Z
  Request complete

failed { message: 'Unable to parse/serialize body',
  body: '{"took":2,"timed_out":false,"_shards":{"total":3,"successful":3,"failed":0},"hits":{"total":1,"max_score":0.19178301,"hits":[{"_index":"places","_type":"snackbar","_id":"1","_score":0.19178301, "_source" : {heading:"Het Geveltje", text: "Foo"}}]}}',
  status: 200 }

I don't understand what I'm doing wrong here?

@spalger
Copy link
Contributor

spalger commented Jan 8, 2014

Doesn't look like you are doing anything wrong. There is an error in the JSON, in the _source field... Can you try running the requests with curl to see if you get the same response body?

curl 'http://localhost:9200/places/snackbar/_search?pretty=true' -XPOST -d '{
  "query": {
    "match": {
      "heading": "het"
    }
  }
}'

@wires
Copy link
Author

wires commented Jan 9, 2014

Good, I thought so. This is the curl output:

{
  "took" : 14,
  "timed_out" : false,
  "_shards" : {
    "total" : 3,
    "successful" : 3,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.19178301,
    "hits" : [ {
      "_index" : "places",
      "_type" : "snackbar",
      "_id" : "1",
      "_score" : 0.19178301, "_source" : {heading:"Het Geveltje", text: "Foo"}
    } ]
  }
}

I don't see a JSON error in the source field? Or do you mean that the error msg implies that there should be one?

@spalger
Copy link
Contributor

spalger commented Jan 9, 2014

The heading and text keys need to be wrapped in quotes for it to be valid json

@spalger
Copy link
Contributor

spalger commented Jan 9, 2014

What version of Elasticsearch are you running?

@spalger
Copy link
Contributor

spalger commented Jan 9, 2014

Looks like you are indexing invalid JSON. Elasticsearch will still parse it sometimes, and when it succeeds it will return the original source to you. elastic/elasticsearch#586

Can you verify that this is the case?

@wires
Copy link
Author

wires commented Jan 9, 2014

Running latest, 0.90.9. But indeed, that was the case, indexed invalid JSON! This was confusing though, missed those quotes. Thanks a lot!

@wires wires closed this as completed Jan 9, 2014
@panthershark
Copy link

I ran into this today. We are using a river to load data. I deleted the indexes and the rivers, then re-added them and things were better.

Hopefully that helps others. This thread was very helpful for me.

@lilac
Copy link

lilac commented Aug 28, 2014

This helps me too.

cdituri pushed a commit to cdituri/elasticsearch-js that referenced this issue Jun 14, 2017
…06064946

Exec tachikoma update 20150706064946
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants