Elastic search exception error in magento2 - elasticsearch

I have configured elastic search in magento2 after that will get exception error below :
I am not able to replicate where exactly the issue. Please help me out.
report.CRITICAL: {"error":{"root_cause":[{"type":"parsing_exception","reason":"Unknown key for a START_OBJECT in [from].","line":1,"col":9}],"type":"parsing_exception","reason":"Unknown key for a START_OBJECT in [from].","line":1,"col":9},"status":400}
\"index_uuid\":\"E4sGUgAESdGLiRcn_lh-iw\",\"index\":\"magento2_product_1_v1\",\"caused_by\":{\"type\":\"number_format_exception\",\"reason\":\"For input string: \\\"sdasd\\\"\"}}}]},\"status\":400} at /app/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:636)"}{
"match" : {
"_search" : {
"query" : "sdasd",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : true,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"boost" : 2.0
}
}
},
{
"match" : {
"name" : {
"query" : "sdasd",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : true,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"boost" : 11.0
}
}
},
{
"match" : {
"sku" : {
"query" : "sdasd",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : true,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"boost" : 8.0
}
}
},
{
"match" : {
"manufacturer_value" : {
"query" : "sdasd",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : true,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"boost" : 7.0
}
}
},
{
"match" : {
"short_description" : {
"query" : "sdasd",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : true,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"boost" : 6.0
}
}
},
{
"match" : {
"color_value" : {
"query" : "sdasd",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : true,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"boost" : 2.0
}
}
},
{
"match" : {
"price_0_1" : {
"query" : "sdasd",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : true,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"boost" : 2.0
}
}
},
{
"match" : {
"tax_class_id_value" : {
"query" : "sdasd",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : true,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"boost" : 2.0
}
}
}
],
"adjust_pure_negative" : true,
"minimum_should_match" : "1",
"boost" : 1.0
}
}\"index_uuid\":\"E4sGUgAESdGLiRcn_lh-iw\",\"index\":\"magento2_product_1_v1\",\"caused_by\":{\"type\":\"number_format_exception\",\"reason\":\"For input string: \\"sdasd\\"\"}}}]},\"status\":400} at /app/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:636)"}

Related

How do I query nested with normal match query together?

I want to fire nestedQuery on addresses and multiMatchQuery on name in single query. I tried few ways but I am getting "[bool] query does not support [nested]". I don't know whether this is possible or not (ES version: 7.x).
When I separately querying (i.e.nestedQuery() & multiMatchQuery()) that time it is working fine.
Please help me with that.
This is the mapping I am using:
{
"employee" : {
"mappings" : {
"properties" : {
"addresses" : {
"type" : "nested",
"properties" : {
"permanentAddress" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"TemporaryAddress" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
1. {
"query": {
"nested": {
"path": "addresses",
"query": {
"bool": {
"must": [
{ "match": { "addresses.permanentAddress": "xxx" } }
]
}
},
"score_mode": "avg"
}
}
}
2. {
"query": {
"bool": {
"must" : [
{
"multi_match" : {
"query" : "xxx",
"fields" : [
"name^1.0"
],
"type" : "best_fields",
"boost" : 1.0
}
}
]
}
}
}
nestedQuery() = looking for xxx value in addresses.permanentAddress
multi_match() = looking for xxx value in name
If value of name or addresses.permanentAddress matches with xxx then returns the result.
"bool" : {
"should" : [
{
"bool" : {
"must" : [
{
"match" : {
"name" : {
"query" : "xxx",
"operator" : "AND",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : true,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"boost" : 1.0
}
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
{
"nested" : {
"query" : {
"bool" : {
"must" : [
{
"match" : {
"employee.permanentAddress" : {
"query" : "xxx",
"operator" : "AND",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : true,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"boost" : 1.0
}
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"path" : "employee",
"ignore_unmapped" : false,
"score_mode" : "none",
"boost" : 1.0,
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
This Bool query with nested worked for me and with that I can able to check parent's as well as nested property.

Elastic search fetch +1 and -1 docuemnt for an id with sort and filter query

I have a query, this query returns a document and I have to retrieve the doc+1 and doc-1. Any suggestions. I cannot afford to do split this query?
EDIT:
The query:
{
"bool" : {
"must" : [
{
"match" : {
"company_id" : {
"query" : "5d10b28a05b69a01f9284913",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : true,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"boost" : 1.0
}
}
}
],
"must_not" : [
{
"terms" : {
"status" : [
"IN_ACTIVE"
],
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}

Elastic Search always returning score as zero

I ran the index and I am trying to execute few queries to validate the data. I found that whatever request I sent the elastic search score is zero for all the results. I am trying different combinations in Kibana and all are documents returned contains _score as zero.
Below is my request and response:
GET _search
{
"version": true,
"size": 500,
"sort": [
{
"_score": {
"order": "desc"
}
}
],
"_source": {
"excludes": []
},
"stored_fields": [
"*"
],
"script_fields": {},
"docvalue_fields": [],
"query": {
"bool": {
"must": [],
"filter": [
{
"match_all": {}
},
{
"match_phrase": {
"name": {
"query": "RED"
}
}
}
],
"should": [],
"must_not": []
}
},
"highlight": {
"pre_tags": [
"#kibana-highlighted-field#"
],
"post_tags": [
"#/kibana-highlighted-field#"
],
"fields": {
"*": {}
},
"fragment_size": 2147483647
}
}
Response is :
{
"took" : 126,
"timed_out" : false,
"_shards" : {
"total" : 11,
"successful" : 11,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 0.0,
"hits" : [
{
"_index" : "products",
"_type" : "product",
"_id" : "11",
"_version" : 3,
"_score" : 0.0,
"_source" : {
"sellercode" : "1",
"avgreviews" : 5.0,
"saleprice" : null,
"sellable" : null,
"freedelivery" : false,
"promotedprice" : null,
"listprice" : 1200.2,
"noofreviews" : 1,
"outdooruse" : false,
"warrantycode" : null,
"australiasellable" : true,
"newrelease" : null,
"sku" : "VSTALDBED386_1",
"height" : 68.0,
"shortdescription" : "Loft Sofa Bed Wood Red Medium",
"commercialuse" : true,
"customisable" : true,
"weight" : "5656.0KG",
"typeCode" : "Bed - King Single",
"colour" : "Red",
"depth" : 51.0,
"name" : "LOFT SOFA BED WOOD RED MEDIUM",
"online" : true,
"materialcode" : "Fabric",
"assemblyrequired" : null,
"category" : [ ],
"stylecode" : "Contemporary"
},
"highlight" : {
"name" : [
"LOFT SOFA BED WOOD #kibana-highlighted-field#RED#/kibana-highlighted-field# MEDIUM"
]
}
},
{
"_index" : "products",
"_type" : "product",
"_id" : "53",
"_version" : 3,
"_score" : 0.0,
"_source" : {
"sellercode" : "1",
"avgreviews" : 5.0,
"saleprice" : null,
"sellable" : null,
"freedelivery" : true,
"promotedprice" : null,
"listprice" : 9635.0,
"noofreviews" : 1,
"outdooruse" : false,
"warrantycode" : null,
"australiasellable" : true,
"newrelease" : null,
"sku" : "VSTALDBED393_1",
"height" : 66.0,
"shortdescription" : "tolix Stool Wood Red",
"commercialuse" : false,
"customisable" : false,
"weight" : "6525.0KG",
"typeCode" : "Bar Stool",
"colour" : "Silver",
"depth" : 25.0,
"name" : "LILLI / TOLIX STOOL WOOD RED",
"online" : true,
"materialcode" : "Metal",
"assemblyrequired" : null,
"category" : [ ],
"stylecode" : "Retro"
},
"highlight" : {
"name" : [
"LILLI / TOLIX STOOL WOOD #kibana-highlighted-field#RED#/kibana-highlighted-field#"
]
}
},
{
"_index" : "products",
"_type" : "product",
"_id" : "125",
"_version" : 3,
"_score" : 0.0,
"_source" : {
"sellercode" : "1",
"avgreviews" : 3.0,
"saleprice" : null,
"sellable" : null,
"freedelivery" : true,
"promotedprice" : null,
"listprice" : 6500.0,
"noofreviews" : 1,
"outdooruse" : false,
"warrantycode" : null,
"australiasellable" : true,
"newrelease" : null,
"sku" : "VSTALDBED405_1",
"height" : 55.0,
"shortdescription" : "Ialian Design New GasLift Chanelle Queen Size Red PU Leather Wodden
Bed frame",
"commercialuse" : false,
"customisable" : false,
"weight" : "5693.0KG",
"typeCode" : "Bed - Queen",
"colour" : "red",
"depth" : 58.0,
"name" : "ITALIAN DESIGN NEW GASLIFT CHANELLE QUEEN SIZE RED PU LEATHER WOODEN BED FRAME",
"online" : true,
"materialcode" : "Timber",
"assemblyrequired" : null,
"category" : [ ],
"stylecode" : "Contemporary"
},
"highlight" : {
"name" : [
"ITALIAN DESIGN NEW GASLIFT CHANELLE QUEEN SIZE #kibana-highlighted-field#RED#/kibana-highlighted-field# PU LEATHER WOODEN BED FRAME"
]
}
},
{
"_index" : "products",
"_type" : "product",
"_id" : "707",
"_version" : 3,
"_score" : 0.0,
"_source" : {
"sellercode" : "2",
"avgreviews" : 2.0,
"saleprice" : null,
"sellable" : null,
"freedelivery" : false,
"promotedprice" : null,
"listprice" : 6326.0,
"noofreviews" : 1,
"outdooruse" : false,
"warrantycode" : null,
"australiasellable" : true,
"newrelease" : null,
"sku" : "VSTALDBED478_2",
"height" : 36.0,
"shortdescription" : "Leaf and Vine Rug Brown Cream red",
"commercialuse" : false,
"customisable" : true,
"weight" : "6548.0KG",
"typeCode" : "Shag Rug",
"colour" : "Brown",
"depth" : 47.0,
"name" : "LEAF AND VINE RUG BROWN CREAM RED",
"online" : true,
"materialcode" : "Plastic",
"assemblyrequired" : null,
"category" : [ ],
"stylecode" : "Contemporary"
},
"highlight" : {
"name" : [
"LEAF AND VINE RUG BROWN CREAM #kibana-highlighted-field#RED#/kibana-highlighted-field#"
]
}
}
]
}
}
Can you point me to right direction tofix this score value.
Thanks.
Sree, all you need is to use your match_phrase in the must clause instead of the filter
Your query part should look like this :
"query": {
"bool": {
"must": [
{
"match_phrase": {
"name": {
"query": "RED"
}
}
}
],
"filter": [
{
"match_all": {}
}
],
"should": [],
"must_not": []
}
}
Output with 1 indexed document :
{
"took" : 7,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "someidx",
"_type" : "_doc",
"_id" : "c37m5W4BifZmUly9Ni-X",
"_version" : 1,
"_score" : 0.2876821,
"_source" : {
"sellercode" : "1",
"avgreviews" : 5.0,
"saleprice" : null,
"sellable" : null,
"freedelivery" : false,
"promotedprice" : null,
"listprice" : 1200.2,
"noofreviews" : 1,
"outdooruse" : false,
"warrantycode" : null,
"australiasellable" : true,
"newrelease" : null,
"sku" : "VSTALDBED386_1",
"height" : 68.0,
"shortdescription" : "Loft Sofa Bed Wood Red Medium",
"commercialuse" : true,
"customisable" : true,
"weight" : "5656.0KG",
"typeCode" : "Bed - King Single",
"colour" : "Red",
"depth" : 51.0,
"name" : "LOFT SOFA BED WOOD RED MEDIUM",
"online" : true,
"materialcode" : "Fabric",
"assemblyrequired" : null,
"category" : [ ],
"stylecode" : "Contemporary"
},
"highlight" : {
"name" : [
"LOFT SOFA BED WOOD #kibana-highlighted-field#RED#/kibana-highlighted-field# MEDIUM"
]
}
}
]
}
}

search full-text with wildcard in elasticsearch

I want to search this phrase "any string that has AT1 or any string that has pro" in filed "text". this is part of my query :
"query_string" : {
"query" : "text:*AT1* *pro*",
"fields" : [ ],
"use_dis_max" : true,
"tie_breaker" : 0.0,
"default_operator" : "or",
"auto_generate_phrase_queries" : false,
"max_determinized_states" : 10000,
"enable_position_increments" : true,
"fuzziness" : "AUTO",
"fuzzy_prefix_length" : 0,
"fuzzy_max_expansions" : 50,
"phrase_slop" : 0,
"escape" : false,
"split_on_whitespace" : true,
"boost" : 1.0,
"allow_leading_wildcard": true,
"analyze_wildcard":true
}
but it doesn't work.it shows all documents.where is my problem?
Your query should be like:
{
"query": {
"query_string": {
"default_field": "text",
"query": "at1 AND pro"
}
}
}
Also, you can read the documentation about full-text queries and compound queries because exists a many ways to solve your problem

ElasticSearch should query

I want to create ElasticSearch query which would be the same as this SQL query
select *
from main.adverts
where user_id = 4
and
(title ilike '%продать / купить%'
or description ilike '%продать / купить%'
)
My attempt is:
{
"query" :{
"bool" : {
"must" : [
{
"term" : {
"user.id" : {
"value" : 4,
"boost" : 1.0
}
}
}
],
"should" : [
{
"bool" : {
"must" : [
{
"match" : {
"title" : {
"query" : "продать",
"operator" : "OR",
"fuzzy_transpositions" : false,
"boost" : 1.0
}
}
},
{
"wildcard" : {
"title" : {
"wildcard" : "купить*",
"boost" : 1.0
}
}
}
],
"disable_coord" : false,
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
{
"bool" : {
"must" : [
{
"match" : {
"description" : {
"query" : "продать",
"operator" : "OR",
"fuzzy_transpositions" : false,
"boost" : 1.0
}
}
},
{
"wildcard" : {
"description" : {
"wildcard" : "купить*",
"boost" : 1.0
}
}
}
],
"disable_coord" : false,
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"disable_coord" : false,
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
}
But it doesn't work correctly. As the result of this query I got records which doesn't contain phrase "продать / купить".
I think that problem is in the "should" part of ElasticSearch query but can't get where is particular.
Could you point me where is my mistake?
It seems that I've found solution
{
"from" : 0, "size" : 60,
"_source" : ["title", "description"],
"query" :{
"bool" : {
"must" : [
{
"term" : {
"user.id" : {
"value" : 4,
"boost" : 1.0
}
}
},
{
"bool" : {
"must" : [
{
"match" : {
"title" : {
"query" : "продать",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : false,
"lenient" : false,
"zero_terms_query" : "NONE",
"boost" : 1.0
}
}
},
{
"wildcard" : {
"title" : {
"wildcard" : "купить*",
"boost" : 1.0
}
}
}
],
"should" : [
{
"bool" : {
"must" : [
{
"match" : {
"description" : {
"query" : "продать",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : false,
"lenient" : false,
"zero_terms_query" : "NONE",
"boost" : 1.0
}
}
},
{
"wildcard" : {
"description" : {
"wildcard" : "купить*",
"boost" : 1.0
}
}
}
],
"disable_coord" : false,
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"disable_coord" : false,
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"disable_coord" : false,
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
}

Resources