Random InternalServerError in ElasticSearch - elasticsearch

We're keeping getting the following error randomly on random query in ElasticSearch.
{
\"status\":500,
\"displayName\":\"InternalServerError\",
\"message\":\"JsonParseException[Unrecognized token 'ards': was expecting ('true', 'false' or 'null')\n at [Source: [B#4103c9af; line: 1, column: 38]]\",
\"body\":{
\"error\":\"JsonParseException[Unrecognized token 'ards': was expecting ('true', 'false' or 'null')\n at [Source: [B#4103c9af; line: 1, column: 38]]\",\"status\":500
}
}
It even happen when we run a very simple query e.g.
{
"from":0,
"size":9,
"query":{
"terms":{
"id": [496161,496895,500119,544238,547116,547302,547364,633486,657141]
}
}
}
BTW, the same query without one of the ids passes without an error.

Seems to be the same issue as in the link bellow, the cause is you have indexed a first document with ... as a boolean.
https://discuss.elastic.co/t/reason-unrecognized-token-john-was-expecting-true-false-or-null/29700
You might want to check the actual mapping at <host>:<port>/<index>/<type>/_mapping.

Somewhere you should use a bool or select as null but you are inserting ards there
Search your queries for ards and replace it with a bool statement

Related

Elasticsearch cannot index array of integers

Given mapping:
{
"mappings": {
"properties": {
"user_ids": {"type": "integer"}
}
}
}
Observations:
Index {"user_ids": 1}, and data will show up correctly
Index {"user_ids": "x"}, and error is thrown failed to parse field [user_ids] of type [integer] in document, indicating that mapping is working correctly
However, indexing {"user_ids": [1]} just clears the field, without throwing error.
Question:
Why does this happen and how can I index arrays of integers?
Extra:
I removed all settings config, doesn't change anything
I tried keyword type, doesn't change anything
If relevant, I use latest opensearch-py
It's not clear what do you mean by clear the field, also indexing array of integers works perfectly fine as shown in below example, hope you are following same requests.
put <index-name>/_doc/1
{
"user_ids": [
1,2,3
]
}
And get API returns, all the integers in the array.
GET <index-name>/_doc/1
"_source": {
"user_ids": [
1,
2,
3
]
}
}
Turns out it's my own error: I was using elasticsearch-head for quick checking of values, and they don't support displaying of array values :/ Once I double checked with queries, they came back correct.

How can i provide a a value for an argument in GraphQL?

I'm very new to GraphQL, and i'm trying to perform some example queries to this graph. In particular i'm trying the User schema.
According to that documentation, the schema is the following:
id: ID!
liquidityPositions: [LiquidityPosition!]
usdSwapped: BigDecimal!
And here is query i tried:
{
user (where: {id: "0x7c9C48b7cBEbBDA3268435F20c81f15A538C566C"}) {
id
liquidityPositions
usdSwapped
}
}
This query fails, i keep getting the following response:
{
"errors": [
{
"locations": [
{
"line": 0,
"column": 0
}
],
"message": "No value provided for required argument: `id`"
}
]
}
How can i provide the id field and where am i supposed to provide it? Thanks in advance!
You've got a couple of problems with that query. First, to get a user by id, remove the "where" and curly braces from your query. Secondly, the liquityPositions field needs a selection of subfields. Like so:
{
user (id: "0x7c9C48b7cBEbBDA3268435F20c81f15A538C566C") {
id
liquidityPositions {
id
}
usdSwapped
}
}
That website you linked to will show you errors with your query so you can interactively learn more about what is supported.
I would also suggest running through the introduction to GraphQL here: https://graphql.org/learn/ to get a handle on how things are done.

Elasticsearch 7 number_format_exception for input value as a String

I have field in index with mapping as :
"sequence_number" : {
"type" : "long",
"copy_to" : [
"_custom_all"
]
}
and using search query as
POST /my_index/_search
{
"query": {
"term": {
"sequence_number": {
"value": "we"
}
}
}
}
I am getting error message :
,"index_uuid":"FTAW8qoYTPeTj-cbC5iTRw","index":"my_index","caused_by":{"type":"number_format_exception","reason":"For input string: \"we\""}}}]},"status":400}
at org.elasticsearch.client.RestClient.convertResponse(RestClient.java:260) ~[elasticsearch-rest-client-7.1.1.jar:7.1.1]
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:238) ~[elasticsearch-rest-client-7.1.1.jar:7.1.1]
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:212) ~[elasticsearch-rest-client-7.1.1.jar:7.1.1]
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1433) ~[elasticsearch-rest-high-level-client-7.1.1.jar:7.1.1]
at
How can i ignore number_format_exception errors, so the query just doesn't return anything or ignores this filter in particular - either is acceptable.
Thanks in advance.
What you are looking for is not possible, ideally, you should have coherce enabled on your numeric fields so that your index doesn't contain dirty data.
The best solution is that in your application which generated the Elasticsearch query(you should have a check for NumberFormatExcepton if you are searching for numeric fields as your index doesn't contain the dirty data in the first place and reject the query if you get an exception in your application).
Edit: Another interesting approach is to validate the data before inserting into ES, using the Validate API as suggested by #prakash, only thing is that it would add another network call but if your application is not latency-sensitive, it can be used as a workaround.

Error while accessing nested JSON object

This is a sample row in my RethinkDB table.
{
"a1": "val1" ,
"a2": "val2" ,
"a3": "val3" ,
"a4": "val4" ,
"part": [
{
"id": "reql" ,
"position": "student"
} ,
{
"id": "sdsadda" ,
"position": "officer"
}
] ,
"a5": "val5"
}
I want to access a nested json object but I get the error e: Cannot perform bracket on a non-object non-sequence "string"
I need the entire row in the output for rows matching id to "reql"
This is my query
r.db('dbname').table('tablename').filter(r.row('part').contains(function(product) {
return product('id').eq("reql");
}))
This query worked before .It doesn't right now.
You'd get that error if you'd somehow ended up with an element in your part array that's a string instead of an object. Try running .filter(r.row('part').contains(function(product) { return product.typeOf().ne('OBJECT'); }), that should return all the rows that have a string in the part array.
Regarding your comment #Puja, I think this should do it for you:
r.db('dbname').table('tablename').filter(function(d){
d("part").typeOf().eq("ARRAY");
}).filter(r.row('part').contains(function(d) {
return d('id').eq("reql");
}))
Although, this is less efficient than #mlucy's answer, and you should definitely just do the one pass over your dataset to clean it up by fixing all the documents where part: STRING.

update document in elasticsearch

I am using Elasticsearch by Restclient in Firefox adds-on
and I have the following problem when updating a document
{
"error": "JsonParseException[Unexpected character (':' (code 58)): was expecting comma to separate OBJECT entries
at [Source: [B#142d626; line: 3, column: 12]]",
"status": 500
}
and i do this
method : post
url: http://localhost:9200/test2/t2/2/_update?pretty
in body
{ "doc" :
"name":"oooooo"
}
any help
thanks
Try with the following JSON in your body:
{
"doc": {
"name": "oooooo"
}
}
In order to do a partial update, the JSON in the body must have a single doc field which contains the fields to update, in this case "name": "oooooo". In your case, you were simply missing the curly braces around the name field.

Resources