Issue
When trying to use angular js $http to post a request to elasticSearch I get an "Unexpected token : " Error.
My code looks like this:
var request= $http({
method: "post",
url: path,
accept:"*/*",
headers:{"Content-Type" : "application/x-www-form-urlencoded; charset: UTF-8"},
data:{
"query":{
"fuzzy":{
"title":{
"value": $scope.searchTerm,
"fuzziness":"1"
}
}
},
"highlight":{
"fields":{
"*":{}
}
}
}
});
When looking in the form data section on chrome console I see the json with a trailing colon.
[{"query":{"fuzzy":{"title":{"value": $scope.searchTerm,"fuzziness":"1"}}},
"highlight":{"fields":{"*":{}}}}]: <--- this is the problem
That is strange. Any ideas on how to eliminate the trailing colon?
Solution
For anyone who encounter this kind of behavior,
In my case it was because I indexed a document with wrong JSON structure. When using the bulk indexing option with elasticSearch - JSONs with invalid structure are indexed without warning.
The error was actually in the response , not on the http request.
Try re-indexing the document which will probably fix this issue.
Answered By - Itzik Gili
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.