Skip to content

Commit 979aee0

Browse files
AC-700 Fixed ElasticSearch sort order incorrect for Custom attribute
1 parent b7db2b2 commit 979aee0

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/StaticField.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function getField(AbstractAttribute $attribute): array
150150
$fieldMapping[$fieldName]['index'] = $index;
151151
}
152152

153-
if ($attributeAdapter->isSortable()) {
153+
if ($attributeAdapter->isSortable() && !$attributeAdapter->isComplexType()) {
154154
$sortFieldName = $this->fieldNameResolver->getFieldName(
155155
$attributeAdapter,
156156
['type' => FieldMapperInterface::TYPE_SORT]
@@ -188,6 +188,20 @@ public function getField(AbstractAttribute $attribute): array
188188
$fieldMapping[$childFieldName] = [
189189
'type' => $this->fieldTypeConverter->convert(FieldTypeConverterInterface::INTERNAL_DATA_TYPE_STRING)
190190
];
191+
if ($attributeAdapter->isSortable()) {
192+
$sortFieldName = $this->fieldNameResolver->getFieldName(
193+
$attributeAdapter,
194+
['type' => FieldMapperInterface::TYPE_SORT]
195+
);
196+
$fieldMapping[$childFieldName]['fields'][$sortFieldName] = [
197+
'type' => $this->fieldTypeConverter->convert(
198+
FieldTypeConverterInterface::INTERNAL_DATA_TYPE_KEYWORD
199+
),
200+
'index' => $this->indexTypeConverter->convert(
201+
IndexTypeConverterInterface::INTERNAL_NO_ANALYZE_VALUE
202+
)
203+
];
204+
}
191205
}
192206

193207
return $fieldMapping;

app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/Product/FieldProvider/StaticFieldTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,34 @@ public function attributeProvider(): array
278278
],
279279
],
280280
],
281+
[
282+
'attr_code',
283+
'select',
284+
false,
285+
false,
286+
'select',
287+
true,
288+
false,
289+
'attr_code_value',
290+
'',
291+
'sort_attr_code',
292+
[
293+
'attr_code_value' => [
294+
'type' => 'select',
295+
'index' => false,
296+
'fields' => [
297+
'sort_attr_code' => [
298+
'type' => 'string',
299+
'index' => 'not_analyzed',
300+
],
301+
],
302+
],
303+
'store_id' => [
304+
'type' => 'string',
305+
'index' => 'no',
306+
],
307+
],
308+
],
281309
[
282310
'attr_code',
283311
'text',

0 commit comments

Comments
 (0)