Kibana am getting this, parsing_exception : [multi_match] unknown token [START_OBJECT] after [query] error - elasticsearch

Am trying to fetch records from elasticsearch via kibana using multi_match query but am getting error response.
Please find my multi match query below.
GET /_search
{
"query": {
"multi_match" : {
"query": {
"prefix" : { "code" : "M" }
}
"fields": [ "code", "_id" ]
}
}
}
Am getting the below error response.
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[multi_match] unknown token [START_OBJECT] after [query]",
"line": 4,
"col": 15
}
],
"type": "parsing_exception",
"reason": "[multi_match] unknown token [START_OBJECT] after [query]",
"line": 4,
"col": 15
},
"status": 400
}

You cannot combine a prefix query with multi_match, depending on your mapping, you might be able to do it like this instead:
GET /_search
{
"query": {
"query_string" : {
"default_field" : "*",
"query" : "M*"
}
}
}

Related

Error message - Unable to filter min_docs_count

EDIT:
Answer below
getting always following error when trying any aggregated query.
Tried googling and different aggregation constructs.
Elasticsearch API Hosted as "Logs Data Platform" by OVH.
Request
{
"aggs" : {
"servers" : {
"filter" : { "term": { "servertype": "1" } },
"aggs" : {
"avg_price" : { "avg" : { "field" : "serveramount" } }
}
}
}
}
Error response
{
"error": {
"root_cause": [
{
"type": "parse_exception",
"reason": "Unable to filter min_docs_count"
}
],
"type": "parse_exception",
"reason": "Unable to filter min_docs_count",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "[size] parameter cannot be negative, found [-1]"
}
},
"status": 400
}
Stupid me ... size=0 was missing in the query parameter.

Elasticsearch Query + Agg search query

Data in my elasticsearch contains a field named facilityName. I have a requirement where I have to see if there are any duplicate records with facilityNameTypeCode as "UWI" and having same facilityName value. Following is a structure example:
"facilityName": [
{
"facilityNameTypeId": {
"facilityNameTypeCode": "Name"
},
"facilityName": "Rishav jayswal"
},
{
"facilityNameTypeId": {
"facilityNameTypeCode": "Name"
},
"facilityName": "R.M"
}
]
This is the query I created:
GET _search
{
"query" : {
"term" : {"facilityName.facilityNameTypeId.facilityNameTypeCode" : "UWI"}
},
"aggs" : {
"duplicateNames": {
"terms": {
"field": "facilityName.facilityName",
"size": 0,
"min_doc_count": 2
}
}
}
}
But I am having this error:
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[terms] failed to parse field [size]",
"line": 10,
"col": 27
}
],
"type": "parsing_exception",
"reason": "[terms] failed to parse field [size]",
"line": 10,
"col": 27,
"caused_by": {
"type": "illegal_argument_exception",
"reason": "[size] must be greater than 0. Found [0] in [duplicateNames]"
}
},
"status": 400
}
Can anyone suggest on how to do this?
The error is pretty clear
[size] must be greater than 0. Found [0] in [duplicateNames]
So simply set size to something bigger than 0, it doesn't make much sense to set it to 0 anyway
"terms": {
"field": "facilityName.facilityName",
"size": 10,
"min_doc_count": 2
}

Nested Query Compatibility in Elastic Search 5.6

I have below payload in my REST call (POST) and its working fine Elastic search 2.1.1 but not in ES 5.6.7
{"from":0,"size":5,"sort":[{"releasedDate":{"order":"desc"}}],"query":{"query_string":{"query":{"query":"demo demo*","defaultOperator":"and"}}}}
In ES 5.6.7, I got below exception
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[query_string] unknown token [START_OBJECT] after [query]",
"line": 1,
"col": 96
}
],
"type": "parsing_exception",
"reason": "[query_string] unknown token [START_OBJECT] after [query]",
"line": 1,
"col": 96
},
"status": 400
}
Anyone have any idea why the payload is not working in ES 5.6.7 ??
In ES 5.6.7 you need to write it like this:
{
"from": 0,
"size": 5,
"sort": [
{
"releasedDate": {
"order": "desc"
}
}
],
"query": {
"query_string": {
"query": "demo demo*",
"default_operator": "and"
}
}
}
Find the documentation here.

Elasticsearch has_child query with term and function_score, parsing_exception

Sending post request to elastic search following is the post data
{
"query": {
"has_child" : {
"type" : "sometype",
"score_mode" : "sum",
"query" : {
"term" : {
"somefield" : "somevalue"
},
"function_score" : {
"script_score": {"script": "1"}
}
},
"inner_hits": {}
}
}
}
}
Getting response as malformed query
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[term] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line": 10,
"col": 17
}
],
"type": "parsing_exception",
"reason": "[term] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line": 10,
"col": 17
},
"status": 400
}
Read documentation from this link: https://www.elastic.co/guide/en/elasticsearch/reference/5.4/query-dsl-has-child-query.html
Elasticsearch version: 5.4
You should make sure to wrap your term and function_score queries in a bool/filter query, like this:
{
"query": {
"has_child": {
"type": "sometype",
"score_mode": "sum",
"query": {
"bool": {
"must": [
{
"term": {
"somefield": "somevalue"
}
},
{
"function_score": {
"script_score": {
"script": "1"
}
}
}
]
}
},
"inner_hits": {}
}
}
}

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

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"
}
}
}]
}
}
}

Resources