Elasticsearch multi search api is not working properly - elasticsearch

Im using elasticsearch 8.3.2. Im facing the below issue while using multi search api.
API: https://elasticrunningserver:9200/myindex/_msearch
Payload:
{ }
{"query" : {"match" : { "message": "this is a test"}}}
{"query" : {"match_all" : {}}}
Response:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "key [query] is not supported in the metadata section"
}
],
"type": "illegal_argument_exception",
"reason": "key [query] is not supported in the metadata section"
},
"status": 400
}
Please help me to resolve this.

You need a metadata section for each query
{ }
{"query" : {"match" : { "message": "this is a test"}}}
{ }
{"query" : {"match_all" : {}}}

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.

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

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

change elasticsearch mapping

I am trying to change the mapping using following code:
PUT /in_test/_mapping/keyword
{
"properties" : {
"term" : {
"type" : "text",
"index" : "not_analyzed"
}
}
}
But it is giving an error:
{
"error": {
"root_cause": [
{
"type": "remote_transport_exception",
"reason": "[tiebreaker-0000000000][172.17.0.24:19555][indices:admin/mapping/put]"
}
],
"type": "illegal_argument_exception",
"reason": "Could not convert [term.index] to boolean",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Failed to parse value [not_analyzed] as only [true] or [false] are allowed."
}
},
"status": 400
}
I also tried to recreate the index
by:
PUT /in_test
{
"mappings" : {
"keyword" : {
"properties" : {
"term" : {
"type" : "text",
"index" : "not_analyzed"
}
}
}
}
}
but I got:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [keyword]: Could not convert [term.index] to boolean"
}
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [keyword]: Could not convert [term.index] to boolean",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Could not convert [term.index] to boolean",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Failed to parse value [not_analyzed] as only [true] or [false] are allowed."
}
}
},
"status": 400
}
I also tried to change the _type to keywords but it is still not working.
Basically, I want to search for exact match of string and for that I am referring to this:
https://www.elastic.co/guide/en/elasticsearch/guide/current/_finding_exact_values.html#_term_query_with_text
That documentation page is from Elasticsearch version 2.X (See at the top of the page), and is no longer correct for modern versions of Elasticsearch.
The error you're getting is because "index" now only accepts true or false, and refers to whether or not the property is indexed at all - Since you're searching by this property, you want it to be true (the default).
Instead, try setting the type to "keyword" and it won't be tokenized. https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-keyword-analyzer.html#_definition_5
PUT /in_test
{
"mappings" : {
"keyword" : {
"properties" : {
"term" : {
"type" : "keyword"
}
}
}
}
}

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

Error adding index with mapping to elasticsearch

I am trying to define mapping for elasticsearch but getting the following error (using KIBANA sense in localhost):
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "analyzer [whitespace_analyzer] not found for field [country]"
}
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [package]: analyzer [whitespace_analyzer] not found for field [country]",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "analyzer [whitespace_analyzer] not found for field [country]"
}
},
"status": 400
}
Mapping given :
PUT /worldV
{
"mappings" : {
"package" : {
"properties" : {
"autosuggestionpackagedetail" : {
"type" : "string",
"index" : "not_analyzed"
},
"availability" : {
},
...... so on ....

Resources