Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

illegal_argument_exception when importing multiselect attribute #87

Open
haelbichalex opened this issue May 23, 2019 · 9 comments
Open

Comments

@haelbichalex
Copy link

I have a Magento 2 store connected to the vue-storefront-api.
I created two products and created a multiselect attribute for testing purposes.

On one product I selected one option for the attribute and on the other one I selected multiple options.
Then I get this error when running yarn mage2vs import:

"statusCode":400,"response":"{\"error\":{\"root_cause\":[{\"type\":\"remote_transport_exception\",\"reason\":\"[hja_gcm][172.21.0.3:9300][indices:data/write/update[s]]\"}],\"type\":\"illegal_argument_exception\",\"reason\":\"mapper [color] of different type, current_type [long], merged_type [text]\"},\"status\":400}"},     
at /var/www/node_modules/mage2vuestorefront/src/adapters/nosql/elasticsearch.js:80:15,     
at respond (/var/www/node_modules/elasticsearch/src/lib/transport.js:327:9),     
at checkRespForFailure (/var/www/node_modules/elasticsearch/src/lib/transport.js:267:7),     
at HttpConnector.<anonymous> (/var/www/node_modules/elasticsearch/src/lib/connectors/http.js:165:7),     
at IncomingMessage.wrapper (/var/www/node_modules/lodash/lodash.js:4935:19),     
at IncomingMessage.emit (events.js:194:15),     
at endReadableNT (_stream_readable.js:1125:12),     
at process._tickCallback (internal/process/next_tick.js:63:19)]

When selection only one attribute option on both products or selecting multiple options on both, the error is not appearing.

Any hints would be appreciated! 👍

@janmyszkier
Copy link
Contributor

The current mapping expects the color to be configurable attribute. so product would be :

            "color": 20,

in your case it seems colors are simple text fields. In that case, adjusting
https://github.com/DivanteLtd/vue-storefront-api/blob/master/config/elastic.schema.product.json#L12
should work.
Have in mind, this is not what filters expect and the color filter in vue can not work

@haelbichalex
Copy link
Author

That makes sense, we will refactor our color attribute probably then.

Issue unfortunately occurs also when I use another attribute, for example I tried "material_filter". There I get current_type [text], merged_type [long] but maybe that's caused by the order the products are imported.
Do I have to add this attribute to the elastic.schema.product.json? If yes, what type does it need?

Thanks!

@janmyszkier
Copy link
Contributor

janmyszkier commented May 23, 2019

no, mapping is to define what you want to enforce. We have multiple custom attributes which ES doesn't complain about.

the thing is: once you add data type of text ES assumes the next ones are also text and creates mapping based on this. Just make sure all products return same datatype and ES will be OK without modifying the mapping file. your problem seems to be different product have different value types (one having text in material_filter and one being long in its material_filter)

@haelbichalex
Copy link
Author

ok, then I don't know why ES thinks I have different types. I just created a completely new M2 instance and added a multiselect attribute there:
Bildschirmfoto 2019-05-23 um 10 20 38
Bildschirmfoto 2019-05-23 um 10 20 43
This is what the M2 database contains:
Bildschirmfoto 2019-05-23 um 10 28 13

Does having multiselect attributes work for you?

@janmyszkier
Copy link
Contributor

janmyszkier commented May 23, 2019

🤔 good question. What I normally do for multi select is I return them as a JSON string SET e.g:
[13,14,15] didn't really try or test so this is just a theory BUT my guess is because it has two , then it's guess to be text, and since 13 is a normal number is guessed to be long

@haelbichalex
Copy link
Author

So mabye all multiselect attribute values should be treated as text, also when only one option was selected. E.g. [13] ?!

@pkarw
Copy link
Contributor

pkarw commented May 23, 2019

@haelbichalex please check how “color_options” are defined. I belive that you should always warp the single values with just an array “[value]” to be 1000% on the safe side. Please make sure you ran “yarn db rebuild” in order to apply the shenanigans changes

@haelbichalex
Copy link
Author

@pkarw I don't think this has anything to do with color as it appears on a different attribute as well.
Also I tried to always just return an array here and debugged this item which shows me:

material_filter: [ '13' ],

Also running yarn db rebuild is included in running yarn mage2vs import, which I use for the initial import.
Still I'm getting the same error:

{ Error: Bad Request
    at respond (/var/www/node_modules/elasticsearch/src/lib/transport.js:308:15)
    at checkRespForFailure (/var/www/node_modules/elasticsearch/src/lib/transport.js:267:7)
    at HttpConnector.<anonymous> (/var/www/node_modules/elasticsearch/src/lib/connectors/http.js:165:7)
    at IncomingMessage.wrapper (/var/www/node_modules/lodash/lodash.js:4935:19)
    at IncomingMessage.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1125:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  status: 400,
  displayName: 'BadRequest',
  message: 'Bad Request',
  path: '/_reindex',
  query: {},
  body:
   { took: 246,
     timed_out: false,
     total: 88,
     updated: 0,
     created: 87,
     deleted: 0,
     batches: 1,
     version_conflicts: 0,
     noops: 0,
     retries: { bulk: 0, search: 0 },
     throttled_millis: 0,
     requests_per_second: -1,
     throttled_until_millis: 0,
     failures: [ [Object] ] },
  statusCode: 400,
  response:
   '{"took":246,"timed_out":false,"total":88,"updated":0,"created":87,"deleted":0,"batches":1,"version_conflicts":0,"noops":0,"retries":{"bulk":0,"search":0},"throttled_millis":0,"requests_per_second":-1.0,"throttled_until_millis":0,"failures":[{"index":"vue_storefront_catalog_guf_1558680746","type":"product","id":"2","cause":{"type":"illegal_argument_exception","reason":"mapper [material_filter] of different type, current_type [long], merged_type [text]"},"status":400}]}',
  toString: [Function],
  toJSON: [Function] }

{ Error: Bad Request
    at respond (/var/www/node_modules/elasticsearch/src/lib/transport.js:308:15)
    at checkRespForFailure (/var/www/node_modules/elasticsearch/src/lib/transport.js:267:7)
    at HttpConnector.<anonymous> (/var/www/node_modules/elasticsearch/src/lib/connectors/http.js:165:7)
    at IncomingMessage.wrapper (/var/www/node_modules/lodash/lodash.js:4935:19)
    at IncomingMessage.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1125:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  status: 400,
  displayName: 'BadRequest',
  message: 'Bad Request',
  path: '/_reindex',
  query: {},
  body:
   { took: 246,
     timed_out: false,
     total: 88,
     updated: 0,
     created: 87,
     deleted: 0,
     batches: 1,
     version_conflicts: 0,
     noops: 0,
     retries: { bulk: 0, search: 0 },
     throttled_millis: 0,
     requests_per_second: -1,
     throttled_until_millis: 0,
     failures: [ [Object] ] },
  statusCode: 400,
  response:
   '{"took":246,"timed_out":false,"total":88,"updated":0,"created":87,"deleted":0,"batches":1,"version_conflicts":0,"noops":0,"retries":{"bulk":0,"search":0},"throttled_millis":0,"requests_per_second":-1.0,"throttled_until_millis":0,"failures":[{"index":"vue_storefront_catalog_guf_1558680746","type":"product","id":"2","cause":{"type":"illegal_argument_exception","reason":"mapper [material_filter] of different type, current_type [long], merged_type [text]"},"status":400}]}',
  toString: [Function],
  toJSON: [Function] }

@haelbichalex
Copy link
Author

it's working for now by also parsing the value to an integer in product.js:

else if (customAttribute.attribute_code === 'material_filter') {
    attrValue = [parseInt(customAttribute.value)]
}

This is a workaround though which should probably be handled somewhere and somehow else... I'm just not that into VS yet to do it myself, maybe someone can provide me a starting point 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants