ElasticSearch - Remove English indexing, leave only Bulgarian

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
kdim95
Advanced
Posts: 208
Joined: 26 Aug 2022, 12:17

ElasticSearch - Remove English indexing, leave only Bulgarian

Post by kdim95 » 15 Aug 2023, 14:09

Laravel framework version: 10.16.1
Aimeos Laravel version: 2023.04.*
PHP Version: 8.2.8
Environment: Linux

Hello,

I'd like to remove the ElasticSearch index for english to improve the speed.

These need to be removed from the index:
  • text:content(en)
  • text:name(en)
  • text:url(en)
Only the bulgarian indexing should remain.
What are the steps to do it?
Currently I have the english locale disabled, but it's still being indexed.

This is what the mapping currently looks like:

Code: Select all

"mappings" : {
      "properties" : {
        "attribute" : {
          "type" : "object",
          "enabled" : false
        },
        "base" : {
          "properties" : {
            "orders" : {
              "type" : "long"
            },
            "product" : {
              "properties" : {
                "boost" : {
                  "type" : "float"
                },
                "code" : {
                  "type" : "keyword",
                  "eager_global_ordinals" : true
                },
                "config" : {
                  "type" : "object",
                  "enabled" : false
                },
                "ctime" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd HH:mm:ss"
                },
                "dataset" : {
                  "type" : "keyword"
                },
                "dateend" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd HH:mm:ss"
                },
                "datestart" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd HH:mm:ss"
                },
                "editor" : {
                  "type" : "keyword"
                },
                "id" : {
                  "type" : "keyword",
                  "eager_global_ordinals" : true
                },
                "instock" : {
                  "type" : "integer"
                },
                "label" : {
                  "type" : "keyword",
                  "eager_global_ordinals" : true
                },
                "mtime" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd HH:mm:ss"
                },
                "rating" : {
                  "type" : "float"
                },
                "ratings" : {
                  "type" : "integer"
                },
                "scale" : {
                  "type" : "float"
                },
                "siteid" : {
                  "type" : "keyword",
                  "eager_global_ordinals" : true
                },
                "status" : {
                  "type" : "short"
                },
                "target" : {
                  "type" : "keyword"
                },
                "type" : {
                  "type" : "keyword",
                  "eager_global_ordinals" : true
                },
                "url" : {
                  "type" : "keyword",
                  "eager_global_ordinals" : true
                }
              }
            },
            "score" : {
              "type" : "float"
            },
            "seen" : {
              "type" : "long"
            }
          }
        },
        "catalog" : {
          "type" : "object",
          "enabled" : false
        },
        "domains" : {
          "type" : "keyword"
        },
        "index" : {
          "properties" : {
            "attribute" : {
              "type" : "nested",
              "properties" : {
                "id" : {
                  "type" : "keyword",
                  "eager_global_ordinals" : true
                }
              }
            },
            "attributeid" : {
              "type" : "keyword",
              "eager_global_ordinals" : true
            },
            "catalog" : {
              "type" : "nested",
              "properties" : {
                "id" : {
                  "type" : "keyword",
                  "eager_global_ordinals" : true
                },
                "listtype" : {
                  "type" : "keyword",
                  "eager_global_ordinals" : true
                },
                "position" : {
                  "type" : "integer"
                }
              }
            },
            "catalogid" : {
              "type" : "keyword",
              "eager_global_ordinals" : true
            },
            "price:value(BGN)" : {
              "type" : "float"
            },
            "siteid" : {
              "type" : "keyword",
              "eager_global_ordinals" : true
            },
            "supplier" : {
              "type" : "nested",
              "properties" : {
                "id" : {
                  "type" : "keyword",
                  "eager_global_ordinals" : true
                },
                "listtype" : {
                  "type" : "keyword",
                  "eager_global_ordinals" : true
                },
                "position" : {
                  "type" : "integer"
                }
              }
            },
            "supplierid" : {
              "type" : "keyword",
              "eager_global_ordinals" : true
            },
            "supplierloc" : {
              "type" : "geo_point"
            },
            "tagid" : {
              "type" : "keyword",
              "eager_global_ordinals" : true
            },
            "text:content()" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "text:content(bg)" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "text:content(en)" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "text:name()" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "text:name(bg)" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "text:name(en)" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "text:url()" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "text:url(bg)" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "text:url(en)" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
        "media" : {
          "type" : "object",
          "enabled" : false
        },
        "price" : {
          "type" : "object",
          "enabled" : false
        },
        "product" : {
          "type" : "object",
          "enabled" : false
        },
        "product/property" : {
          "type" : "object",
          "enabled" : false
        },
        "product:has" : {
          "type" : "keyword",
          "eager_global_ordinals" : true
        },
        "product:prop" : {
          "type" : "keyword",
          "eager_global_ordinals" : true
        },
        "supplier" : {
          "type" : "object",
          "enabled" : false
        },
        "text" : {
          "type" : "object",
          "enabled" : false
        }
      }
    }
  }

User avatar
aimeos
Administrator
Posts: 7915
Joined: 01 Jan 1970, 00:00

Re: ElasticSearch - Remove English indexing, leave only Bulgarian

Post by aimeos » 16 Aug 2023, 13:46

The \Aimeos\MShop\Product\Manager\Elastic class contains a getLanguageIds() method which you can overwrite and fetch only active languages.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

kdim95
Advanced
Posts: 208
Joined: 26 Aug 2022, 12:17

Re: ElasticSearch - Remove English indexing, leave only Bulgarian

Post by kdim95 » 16 Aug 2023, 14:33

I understand what I need to change.

Code: Select all

	/**
	 * Returns the language IDs available for the current site
	 *
	 * @return string[] List of ISO language codes
	 */
	protected function getLanguageIds() : array
	{
		if( !isset( $this->languageIds ) )
		{
			$list = [];
			$manager = \Aimeos\MShop::create( $this->context(), 'locale' );
			$items = $manager->search( $manager->filter()->add( 'locale.status', '==', 1 )->slice( 0, 10000 ) );

			foreach( $items as $item ) {
				$list[$item->getLanguageId()] = null;
			}

			$this->languageIds = array_keys( $list );
		}
		
		return $this->languageIds;
	}
How do you override this:
Aimeos\MShop\Product\Manager\Elastic

I tried the following, didn't work:

Code: Select all

'mshop' => [
		'product' => [
			'manager' => [
				'name' => 'ElasticCustom'
			]
		],
]

Code: Select all

<?php

namespace Aimeos\MShop\Product\Manager;

class ElasticCustom extends Elastic
{
    /**
	 * Returns the language IDs available for the current site
	 *
	 * @return string[] List of ISO language codes
	 */
	protected function getLanguageIds() : array
	{
		if( !isset( $this->languageIds ) )
		{
			$list = [];
			$manager = \Aimeos\MShop::create( $this->context(), 'locale' );
			$items = $manager->search( $manager->filter()->add( 'locale.status', '==', 1 )->slice( 0, 10000 ) );

			foreach( $items as $item ) {
				$list[$item->getLanguageId()] = null;
			}

			$this->languageIds = array_keys( $list );
		}
		
		return $this->languageIds;
	}
}

User avatar
aimeos
Administrator
Posts: 7915
Joined: 01 Jan 1970, 00:00

Re: ElasticSearch - Remove English indexing, leave only Bulgarian

Post by aimeos » 16 Aug 2023, 14:39

You have to extend the index/text manager instead because it extends from the product manager. Your custom product manager isn't used when indexing.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

kdim95
Advanced
Posts: 208
Joined: 26 Aug 2022, 12:17

Re: ElasticSearch - Remove English indexing, leave only Bulgarian

Post by kdim95 » 16 Aug 2023, 15:10

Thanks, that worked 👍

Post Reply