{"id":438021,"date":"2024-05-06T07:54:53","date_gmt":"2024-05-06T07:54:53","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=438021"},"modified":"2024-09-24T06:06:15","modified_gmt":"2024-09-24T06:06:15","slug":"customized-sort-order-elasticsearch","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/","title":{"rendered":"Customized sort order in Elasticsearch"},"content":{"rendered":"\n<p>Here will look how we can customize sort order in Elasticsearch by providing the sort order in the array format.<\/p>\n\n\n\n<p>You can also check the <a href=\"https:\/\/store.webkul.com\/Magento2-Elasticsearch.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 Elasticsearch extension<\/a> that provides near real-time search and analytics for all types of data. <\/p>\n\n\n\n<p>Whether you have structured or unstructured text, numerical data, or geospatial data, Elasticsearch can efficiently store and index it to support fast searches.<\/p>\n\n\n\n<p>One of the fundamental strengths of Elasticsearch lies in its&nbsp;<strong>scalability and speed<\/strong>. Its distributed nature allows for horizontal scaling, accommodating growing data needs seamlessly. <\/p>\n\n\n\n<p>Additionally, its near real-time <a href=\"https:\/\/webkul.com\/blog\/magento-2-enhanced-indexer-management\/\" target=\"_blank\" rel=\"noreferrer noopener\">indexing capability<\/a> ensures that data is available for search immediately after ingestion.<\/p>\n\n\n\n<p>Elasticsearch also provides several other sorting techniques by default. However, the customized sort technique is one of my favorites and has several use cases.<\/p>\n\n\n\n<p>To get started, we first need to <a href=\"https:\/\/webkul.com\/blog\/magento-development-01-module-registration\/\" target=\"_blank\" rel=\"noreferrer noopener\">create a module<\/a> in which we write our functionality.<\/p>\n\n\n\n<p>You can also connect with a certified&nbsp;<a href=\"https:\/\/webkul.com\/magento-development\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 development company<\/a>&nbsp;that can assist you with the development of Adobe Commerce extensions.<\/p>\n\n\n\n<p>After creating the module we need to create a plugin to modify the Elasticsearch query. For that, we first define our plugin in the <strong>di.xml<\/strong> file at path <strong>app\/code\/VendorName\/ModuleName\/etc\/di.xml<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:ObjectManager\/etc\/config.xsd&quot;&gt;\n    &lt;type name=&quot;Magento\\Framework\\Search\\AdapterInterface&quot;&gt;\n        &lt;plugin name=&quot;customize_elasticsearch_search_results&quot; type=&quot;Webkul\\CustomizeElasticsearch\\Plugin\\Elasticsearch7\\SearchAdapter\\Adapter&quot; sortOrder=&quot;1&quot; \/&gt;\n    &lt;\/type&gt;\n&lt;\/config&gt;<\/pre>\n\n\n\n<p>After defining the plugin we need to create our plugin file at the location defined in the definition of the plugin.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\nnamespace Webkul\\CustomizeElasticsearch\\Plugin\\Elasticsearch7\\SearchAdapter;\n\nuse Magento\\Framework\\Search\\RequestInterface;\nuse Magento\\Elasticsearch7\\SearchAdapter\\Mapper;\nuse Magento\\Elasticsearch\\SearchAdapter\\ResponseFactory;\nuse Magento\\Elasticsearch\\SearchAdapter\\ConnectionManager;\nuse Magento\\Elasticsearch\\SearchAdapter\\QueryContainerFactory;\nuse Magento\\Elasticsearch\\SearchAdapter\\Aggregation\\Builder as AggregationBuilder;\n\nclass Adapter\n{\n    \/**\n     * @var array\n     *\/\n    private static $emptyRawResponse = &#091;\n        &quot;hits&quot; =&gt;\n        &#091;\n            &quot;hits&quot; =&gt; &#091;]\n        ],\n        &quot;aggregations&quot; =&gt;\n        &#091;\n            &quot;price_bucket&quot; =&gt; &#091;],\n            &quot;category_bucket&quot; =&gt;\n            &#091;\n                &quot;buckets&quot; =&gt; &#091;]\n\n            ]\n        ]\n    ];\n\n    \/**\n     * Dependency Initilization\n     *\n     * @param Mapper $mapper\n     * @param \\Psr\\Log\\LoggerInterface $logger\n     * @param ResponseFactory $responseFactory\n     * @param ConnectionManager $connectionManager\n     * @param AggregationBuilder $aggregationBuilder\n     * @param QueryContainerFactory $queryContainerFactory\n     * @param \\Magento\\Framework\\Message\\ManagerInterface $messageManager\n     * @param \\Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory $collectionFactory\n     *\/\n    public function __construct(\n        private Mapper $mapper,\n        private \\Psr\\Log\\LoggerInterface $logger,\n        private ResponseFactory $responseFactory,\n        private ConnectionManager $connectionManager,\n        private AggregationBuilder $aggregationBuilder,\n        private QueryContainerFactory $queryContainerFactory,\n        private \\Magento\\Framework\\Message\\ManagerInterface $messageManager,\n        private \\Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory $collectionFactory\n    ) {\n    }\n\n    \/**\n     * Add seller product to seller collection\n     *\n     * @param \\Magento\\Framework\\Search\\AdapterInterface $subject\n     * @param callable $proceed\n     * @param RequestInterface $request\n     *\/\n    public function aroundQuery(\n        \\Magento\\Framework\\Search\\AdapterInterface $subject,\n        callable $proceed,\n        RequestInterface $request\n    ) {\n        try {\n            $productIds = $this-&gt;getProductCustomSortOrder();\n            $client = $this-&gt;connectionManager-&gt;getConnection();\n            $aggregationBuilder = $this-&gt;aggregationBuilder;\n            $updatedQuery = $this-&gt;mapper-&gt;buildQuery($request);\n            unset($updatedQuery&#091;&#039;body&#039;]&#091;&#039;query&#039;]&#091;&#039;bool&#039;]&#091;&#039;should&#039;]);\n            unset($updatedQuery&#091;&#039;body&#039;]&#091;&#039;query&#039;]&#091;&#039;bool&#039;]&#091;&#039;minimum_should_match&#039;]);\n            unset($updatedQuery&#091;&#039;body&#039;]&#091;&#039;sort&#039;]);\n            $updatedQuery&#091;&#039;body&#039;]&#091;&#039;sort&#039;]&#091;0]&#091;&#039;_script&#039;]&#091;&#039;type&#039;] = &#039;number&#039;;\n            $setSortOrderAttribute = &#039;params.sortOrder.indexOf(doc&#091;&quot;_id&quot;].value)&#039;;\n            $updatedQuery&#091;&#039;body&#039;]&#091;&#039;sort&#039;]&#091;0]&#091;&#039;_script&#039;]&#091;&#039;script&#039;]&#091;&#039;inline&#039;] = $setSortOrderAttribute;\n            $updatedQuery&#091;&#039;body&#039;]&#091;&#039;sort&#039;]&#091;0]&#091;&#039;_script&#039;]&#091;&#039;script&#039;]&#091;&#039;params&#039;]&#091;&#039;sortOrder&#039;] = $productIds;\n            unset($updatedQuery&#091;&#039;body&#039;]&#091;&#039;sort&#039;]&#091;0]&#091;&#039;_score&#039;]);\n            $updatedQuery&#091;&#039;body&#039;]&#091;&#039;query&#039;]&#091;&#039;bool&#039;]&#091;&#039;filter&#039;] = &#091;&#039;ids&#039; =&gt; &#091;&#039;values&#039; =&gt; $productIds]];\n            $aggregationBuilder-&gt;setQuery($this-&gt;queryContainerFactory-&gt;create(&#091;&#039;query&#039; =&gt; $updatedQuery]));\n            try {\n                $rawResponse = $client-&gt;query($updatedQuery);\n            } catch (\\Exception $e) {\n                $this-&gt;logger-&gt;debug(\n                    &quot;Elasticsearch7_SearchAdapter_Adapter aroundQuery &quot; . $e-&gt;getMessage()\n                );\n                $rawResponse = self::$emptyRawResponse;\n            }\n            $rawDocuments = $rawResponse&#091;&#039;hits&#039;]&#091;&#039;hits&#039;] ?? &#091;];\n            $queryResponse = $this-&gt;responseFactory-&gt;create(\n                &#091;\n                    &#039;documents&#039; =&gt; $rawDocuments,\n                    &#039;aggregations&#039; =&gt; $aggregationBuilder-&gt;build($request, $rawResponse),\n                    &#039;total&#039; =&gt; $rawResponse&#091;&#039;hits&#039;]&#091;&#039;total&#039;]&#091;&#039;value&#039;] ?? 0\n                ]\n            );\n            return $queryResponse;\n        } catch (\\Exception $e) {\n            $this-&gt;logger-&gt;debug(\n                &quot;Elasticsearch7_SearchAdapter_Adapter aroundQuery &quot; . $e-&gt;getMessage()\n            );\n            $this-&gt;messageManager-&gt;addError(__($e-&gt;getMessage()));\n        }\n        return $proceed($request);\n    }\n\n    \/**\n     * Get Product Custom SortOrder\n     *\n     * @return array\n     *\/\n    private function getProductCustomSortOrder()\n    {\n        $products = $this-&gt;collectionFactory-&gt;create()\n            -&gt;addFieldToFilter(&#039;visibility&#039;, &#091;&#039;in&#039; =&gt; &#091;3, 4]]);\n        $evenProductIds = &#091;];\n        $oddProductIds = &#091;];\n        foreach ($products as $product) {\n            if ($product-&gt;getEntityId() % 2 == 0) {\n                $evenProductIds&#091;] = $product-&gt;getEntityId();\n            } else {\n                $oddProductIds&#091;] = $product-&gt;getEntityId();\n            }\n        }\n        return array_merge($oddProductIds, $evenProductIds);\n    }\n}<\/pre>\n\n\n\n<p>The code that actually helps in sorting is.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">$updatedQuery&#091;&#039;body&#039;]&#091;&#039;sort&#039;]&#091;0]&#091;&#039;_script&#039;]&#091;&#039;type&#039;] = &#039;number&#039;;\n$setSortOrderAttribute = &#039;params.sortOrder.indexOf(doc&#091;&quot;_id&quot;].value)&#039;;\n$updatedQuery&#091;&#039;body&#039;]&#091;&#039;sort&#039;]&#091;0]&#091;&#039;_script&#039;]&#091;&#039;script&#039;]&#091;&#039;inline&#039;] = $setSortOrderAttribute;\n$updatedQuery&#091;&#039;body&#039;]&#091;&#039;sort&#039;]&#091;0]&#091;&#039;_script&#039;]&#091;&#039;script&#039;]&#091;&#039;params&#039;]&#091;&#039;sortOrder&#039;] = $productIds;<\/pre>\n\n\n\n<p>Our actual query format looks something like this.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">Array\n(\n    &#091;body] =&gt; Array\n    (\n        &#091;sort] =&gt; Array\n        (\n            &#091;0] =&gt; Array\n            (\n                &#091;_script] =&gt; Array\n                (\n                    &#091;type] =&gt; number\n                    &#091;script] =&gt; Array\n                    (\n                        &#091;inline] =&gt; params.sortOrder.indexOf(doc&#091;&quot;_id&quot;].value)\n                        &#091;params] =&gt; Array\n                        (\n                            &#091;sortOrder] =&gt; Array\n                            (\n                                &#091;0] =&gt; 1\n                                &#091;1] =&gt; 3\n                                &#091;2] =&gt; 5\n                                &#091;3] =&gt; 7\n                                &#091;4] =&gt; 9\n                                &#091;5] =&gt; 2\n                                &#091;6] =&gt; 4\n                                &#091;7] =&gt; 6\n                                &#091;8] =&gt; 8\n                                &#091;9] =&gt; 10\n                            )\n                        )\n                    )\n                )\n            )\n        )\n    )\n)<\/pre>\n\n\n\n<p>Here our sortOrder array contains all the odd product IDs first and all the even product IDs after them which causes our product listing to sort products that way.<\/p>\n\n\n\n<p>According to the above code, our product listing will look like this.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" width=\"1200\" height=\"666\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1-1200x666.webp\" alt=\"Product Listing\" class=\"wp-image-443559\" style=\"width:820px;height:auto\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1-1200x666.webp 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1-300x167.webp 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1-250x139.webp 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1-768x427.webp 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1.webp 1327w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>That&#8217;s all guys we have successfully customized the sort order for our product listing.<\/p>\n\n\n\n<p>You can also find other <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/sort-search-results.html\">sorting techniques<\/a> Elasticsearch provides to understand the Elasticsearch better.<\/p>\n\n\n\n<p>Take the opportunity to browse through our range of <a href=\"https:\/\/store.webkul.com\/Magento-2.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 extensions<\/a>, meticulously created by certified Adobe Commerce Developers.<\/p>\n\n\n\n<p>For a customized experience, bring on board and <a href=\"https:\/\/webkul.com\/hire-magento-developers\/\" target=\"_blank\" rel=\"noreferrer noopener\">hire Magento developers<\/a> who can exclusively focus on your personalized e-commerce projects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>This blog has guided you through the process of customizing the sort order in Elasticsearch for Magento 2, utilizing an array format to achieve a tailored product listing. <\/p>\n\n\n\n<p>By leveraging the scalability and near real-time indexing capabilities of Elasticsearch, you can enhance the search experience for both structured and unstructured data. <\/p>\n\n\n\n<p>We explored the steps required to create a module and a plugin that modifies the Elasticsearch query to implement a customized sorting technique. <\/p>\n\n\n\n<p>With the provided code snippet, you can effectively organize your product listings according to specific criteria. <\/p>\n\n\n\n<p>For further enhancements and additional sorting techniques, exploring other resources and Magento 2 extensions can be beneficial. <\/p>\n\n\n\n<p>If you seek specialized support, consider hiring Magento developers to bring your unique e-commerce vision to life. Thank you for reading, and happy customizing!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here will look how we can customize sort order in Elasticsearch by providing the sort order in the array format. You can also check the Magento 2 Elasticsearch extension that provides near real-time search and analytics for all types of data. Whether you have structured or unstructured text, numerical data, or geospatial data, Elasticsearch can <a href=\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":548,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9121],"tags":[6841,2070,590],"class_list":["post-438021","post","type-post","status-publish","format-standard","hentry","category-magento-2","tag-elasticsearch","tag-magento2","tag-webkul"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Customized sort order in Elasticsearch<\/title>\n<meta name=\"description\" content=\"Elasticsearch also provides several other sorting techniques by default however customized sort technique is one of my favorites.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Customized sort order in Elasticsearch\" \/>\n<meta property=\"og:description\" content=\"Elasticsearch also provides several other sorting techniques by default however customized sort technique is one of my favorites.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-05-06T07:54:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-24T06:06:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1-1200x666.webp\" \/>\n<meta name=\"author\" content=\"Deepesh Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Deepesh Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/\"},\"author\":{\"name\":\"Deepesh Kumar\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/43552f90bbc8fafb784fe138f6d82a0b\"},\"headline\":\"Customized sort order in Elasticsearch\",\"datePublished\":\"2024-05-06T07:54:53+00:00\",\"dateModified\":\"2024-09-24T06:06:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/\"},\"wordCount\":483,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1-1200x666.webp\",\"keywords\":[\"elasticsearch\",\"Magento2\",\"webkul\"],\"articleSection\":[\"Magento 2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/\",\"url\":\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/\",\"name\":\"Customized sort order in Elasticsearch\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1-1200x666.webp\",\"datePublished\":\"2024-05-06T07:54:53+00:00\",\"dateModified\":\"2024-09-24T06:06:15+00:00\",\"description\":\"Elasticsearch also provides several other sorting techniques by default however customized sort technique is one of my favorites.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1.webp\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1.webp\",\"width\":1327,\"height\":737},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Customized sort order in Elasticsearch\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/43552f90bbc8fafb784fe138f6d82a0b\",\"name\":\"Deepesh Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d898f8a790ab5a002f048ad4b4661fda07600235f1338d01ff1fd60152fe4d10?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d898f8a790ab5a002f048ad4b4661fda07600235f1338d01ff1fd60152fe4d10?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Deepesh Kumar\"},\"description\":\"Deepesh Kumar, a proficient Software Engineer, excels in PHP, JavaScript, and database management. Mastery of complex eCommerce systems and Magento&rsquo;s architecture drives innovative solutions and optimizes performance for business success.\",\"url\":\"https:\/\/webkul.com\/blog\/author\/deepeshkumar-mg397\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Customized sort order in Elasticsearch","description":"Elasticsearch also provides several other sorting techniques by default however customized sort technique is one of my favorites.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/","og_locale":"en_US","og_type":"article","og_title":"Customized sort order in Elasticsearch","og_description":"Elasticsearch also provides several other sorting techniques by default however customized sort technique is one of my favorites.","og_url":"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2024-05-06T07:54:53+00:00","article_modified_time":"2024-09-24T06:06:15+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1-1200x666.webp","type":"","width":"","height":""}],"author":"Deepesh Kumar","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Deepesh Kumar","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/"},"author":{"name":"Deepesh Kumar","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/43552f90bbc8fafb784fe138f6d82a0b"},"headline":"Customized sort order in Elasticsearch","datePublished":"2024-05-06T07:54:53+00:00","dateModified":"2024-09-24T06:06:15+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/"},"wordCount":483,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1-1200x666.webp","keywords":["elasticsearch","Magento2","webkul"],"articleSection":["Magento 2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/","url":"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/","name":"Customized sort order in Elasticsearch","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1-1200x666.webp","datePublished":"2024-05-06T07:54:53+00:00","dateModified":"2024-09-24T06:06:15+00:00","description":"Elasticsearch also provides several other sorting techniques by default however customized sort technique is one of my favorites.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1.webp","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2024\/05\/blogimageproductlisting-1.webp","width":1327,"height":737},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/customized-sort-order-elasticsearch\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Customized sort order in Elasticsearch"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/43552f90bbc8fafb784fe138f6d82a0b","name":"Deepesh Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d898f8a790ab5a002f048ad4b4661fda07600235f1338d01ff1fd60152fe4d10?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d898f8a790ab5a002f048ad4b4661fda07600235f1338d01ff1fd60152fe4d10?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Deepesh Kumar"},"description":"Deepesh Kumar, a proficient Software Engineer, excels in PHP, JavaScript, and database management. Mastery of complex eCommerce systems and Magento&rsquo;s architecture drives innovative solutions and optimizes performance for business success.","url":"https:\/\/webkul.com\/blog\/author\/deepeshkumar-mg397\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/438021","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/548"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=438021"}],"version-history":[{"count":19,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/438021\/revisions"}],"predecessor-version":[{"id":464719,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/438021\/revisions\/464719"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=438021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=438021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=438021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}