elasticsearch 5: Unknown key for a START_OBJECT in [filters] - elasticsearch

Im trying to migrate from elasticsearch 1.7 to 5.1 and I have a problem:
curl -XGET http://127.0.0.1:9200/openlist_ru-formulars/formular/_search?pretty=true -d '{
"filter": [
{ "range": { "born": { "gte": "1874" }}}
]
}'
and answer:
{
"error" : {
"root_cause" : [
{
"type" : "parsing_exception",
"reason" : "Unknown key for a START_OBJECT in [filters].",
"line" : 2,
"col" : 12
}
],
"type" : "parsing_exception",
"reason" : "Unknown key for a START_OBJECT in [filters].",
"line" : 2,
"col" : 12
},
"status" : 400
}
I used google all the day but still have no answer what it means. Please help.

It looks like DSL structure in 5.1 version was changed and this query is good:
{
"query": {
"bool": {
"filter": [{
"range": {
"born": {
"gte": "1874"
}
}
}]
}
}
}

Related

malformed query, expected "END_OBJECT" but found "FIELD_NAME"

Hello while running a term query in Kibana console, I am getting a parsing_exception
Query
GET /products/_search
{
"query": {
"terms": {
"tags.keyword": [ "Soup", "Cake" ]
},
"range": {
"in_stock": {
"gte": 10,
"lte": 20
}
}
}
}
Response/Exception
{
"error" : {
"root_cause" : [
{
"type" : "parsing_exception",
"reason" : "[terms] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line" : 6,
"col" : 5
}
],
"type" : "parsing_exception",
"reason" : "[terms] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line" : 6,
"col" : 5
},
"status" : 400
}
Can anyone tell me why I got this exception and how to solve it?
You need to use boolean query to combine terms and range query. Modify your search query as shown below -
{
"query": {
"bool": {
"must": [
{
"terms": {
"tags.keyword": [
"Soup",
"Cake"
]
}
},
{
"range": {
"in_stock": {
"gte": 10,
"lte": 20
}
}
}
]
}
}
}

unknown query [filtered] when doing search against ES

I am new to ES, and I am using ES 7.10.1, I have following simple search request:
GET /megacorp/_doc/_search
{
"query":{
"filtered":{
"filter":{
"range":{
"age":{
"gt":30
}
}
},
"query":{
"match":{
"last_name":"smith"
}
}
}
}
}
When I run the above query(using query and filter) in the Kibana Dev Tools, an exception occurs as follows, I would ask how to fix this,thank.
{
"error" : {
"root_cause" : [
{
"type" : "parsing_exception",
"reason" : "unknown query [filtered]",
"line" : 3,
"col" : 14
}
],
"type" : "parsing_exception",
"reason" : "unknown query [filtered]",
"line" : 3,
"col" : 14,
"caused_by" : {
"type" : "named_object_not_found_exception",
"reason" : "[3:14] unknown field [filtered]"
}
},
"status" : 400
}
The filtered query has been deprecated. You should now use the boolean query. Modify your search query as -
{
"query": {
"bool": {
"must": {
"match": {
"last_name": "smith"
}
},
"filter": {
"range": {
"age": {
"gt": 30
}
}
}
}
}
}

"[geo_distance] malformed query, expected [END_OBJECT] but found [FIELD_NAME]"

I am tried to create search query with a values in 15m radios and between 3 weeks. I tried to execute this query:
"query": {
"bool": {
"must": {
"match_all": {}
}
, "filter": [
{
"geo_distance": {
"distance": "1000km",
"geoLocation": {
"lat": 31.966467334184614,
"lon": 35.83242623178664
}
}
,
"range": {
"map_date": {
"gte": "now-3w/w",
"lte": "now/w"
}
}
}
]
}}
My date filed is: map_date and my geo point filed is geoLocation
I get this response :
{
"error" : {
"root_cause" : [
{
"type" : "parsing_exception",
"reason" : "[geo_distance] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line" : 18,
"col" : 8
}
],
"type" : "x_content_parse_exception",
"reason" : "[18:8] [bool] failed to parse field [filter]",
"caused_by" : {
"type" : "parsing_exception",
"reason" : "[geo_distance] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line" : 18,
"col" : 8
}
},
"status" : 400
}
Help me please to figure out what I am doing wrong
Your filter part was mal formated, try :
{
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": [
{
"geo_distance": {
"distance": "1000km",
"geoLocation": {
"lat": 31.966467334184614,
"lon": 35.83242623178664
}
}
},
{
"range": {
"map_date": {
"gte": "now-3w/w",
"lte": "now/w"
}
}
}
]
}
}
}
Il your filter array you list a list of {}, take a look at:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html

elasticsearch skip completion suggester duplicates

My elasticsearch current version is 6.0.1.
I'm using a completion suggester on my "suggest" field as follow:
GET my_index/_search
{
"suggest": {
"tag-suggest" : {
"prefix" : "black",
"completion" : {
"field" : "suggest",
"size" : 10,
"fuzzy" : {
"fuzziness" : 1
}
}
}
}
}
I'd like to skip duplicates in order to only retrieve unique suggestions.
According to elasticsearch documentation (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html) I can achieve that by turning the option "skip_duplicates" to true:
GET my_index/_search
{
"suggest": {
"tag-suggest" : {
"prefix" : "black",
"completion" : {
"field" : "suggest",
"skip_duplicates": true,
"size" : 10,
"fuzzy" : {
"fuzziness" : 1
}
}
}
}
}
Unfortunately I'm getting the following error:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "[completion] unknown field [skip_duplicates], parser not found"
}
],
"type": "illegal_argument_exception",
"reason": "[completion] unknown field [skip_duplicates], parser not found"
},
"status": 400
}
Unfortunatelly skip_duplicates is not available in your version.
Please take a look here: https://www.elastic.co/guide/en/elasticsearch/reference/6.0/search-suggesters-completion.html
It was introduced in version 6.1: https://www.elastic.co/guide/en/elasticsearch/reference/6.1/search-suggesters-completion.html

failed to parse search source. expected field name but got [START_OBJECT]

I want to express this SQL in Elasticsearch:
select * from ticket where user_id = 1 and (class_a = 1000010 or class_b = 16);
I use a combining filter as below:
curl 'localhost:9200/ticket/_search?pretty' -d'
{
"query": {
"bool": {
"should": [
{"term": {"class_a": 1000010}},
{"term": {"class_b": 16}}
]
},
"filter": {
"term": {
"user_id": 1
}
}
}
}'
but got the error as below:
{
"error" : {
"root_cause" : [ {
"type" : "parse_exception",
"reason" : "failed to parse search source. expected field name but got [START_OBJECT]"
} ],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query_fetch",
"grouped" : true,
"failed_shards" : [ {
"shard" : 0,
"index" : "ticket",
"node" : "FO3-zhb1R1WCak381t88gQ",
"reason" : {
"type" : "parse_exception",
"reason" : "failed to parse search source. expected field name but got [START_OBJECT]"
}
} ]
},
"status" : 400
}
Anyone can help me? Thanks in advance!
You're almost there, you need to rewrite your query like this (i.e. move your filter inside the bool clause):
curl 'localhost:9200/ticket/_search?pretty' -d'{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"term": {
"class_a": 1000010
}
},
{
"term": {
"class_b": 16
}
}
],
"filter": {
"term": {
"user_id": 1
}
}
}
}
}'

Resources