How to delete Elasticsearch indices in Magento 2?

You can delete specific elastic search indices or all the available indices with the help of the Delete command.

You can run the given command to delete a specific index from the elastic search,

curl -X DELETE 'http://localhost:9200/<index_name>'

Continue reading “How to delete Elasticsearch indices in Magento 2?”

How to get list of all Elasticsearch indices in Magento 2?

Magento 2 you can get a list of all indices available for the system, With the help of the CLI command, You can check the status of each indices used for the system.

You can run the given command,
curl -X GET http://localhost:9200/_cat/indices?v

If you have changed your elastic search hostname to something else, You need to replace localhost with your actual name.

For example, curl -X GET http://elasticsearch:9200/_cat/indices?v

You can get the result once the valid URL is available, On a success call, the result looks like this,

health status index                                                uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   magento_default_catalog_product_20230703_022952      bjHqWsUATpGg1xwnnB5YAg   1   0          0            0       283b           283b

With a list of available indices for the system in a response.
Health status green displays your indices status is healthy.

How to use get customer search REST API V1/customers/search in Magento 2?

Magento Customer Search Rest API V1/customers/search is used to search by customer-specific fields. You can use customer search API to fetch results by search criteria builder.

Action: GET

URL: <HOST_URL>/rest/V1/customers/search
(Example, http://magento246.docker/rest/V1/customers/search?searchCriteria[filterGroups][0][filters][0][field]=email&searchCriteria[filterGroups][0][filters][0][value]=rakesh@jesadiya.com&searchCriteria[filterGroups][0][filters][0][conditionType]=eq)

HEADER:
Authorization: Bearer <ADMIN_TOKEN>

You have to pass the admin token detail as HEADER Authorization from the link, Generate the Admin token Rest API

Payload: NULL

Response:

{
    "items": [
        {
            "id": 3,
            "group_id": 1,
            "default_billing": "2",
            "default_shipping": "2",
            "created_at": "2023-10-05 04:54:09",
            "updated_at": "2023-10-06 12:36:01",
            "created_in": "Default",
            "email": "rakesh@jesadiya.com",
            "firstname": "Rakesh",
            "lastname": "Jesadiya",
            "store_id": 1,
            "website_id": 1,
            "addresses": [
                {
                    "id": 2,
                    "customer_id": 3,
                    "region": {
                        "region_code": "Yorkshire",
                        "region": "Yorkshire",
                        "region_id": 0
                    },
                    "region_id": 0,
                    "country_id": "GB",
                    "street": [
                        "my Street",
                    ],
                    "company": "Test",
                    "telephone": "04433333",
                    "postcode": "LS1 5EN",
                    "city": "Leeds",
                    "firstname": "Rakesh",
                    "lastname": "Jesadiya",
                    "default_shipping": true,
                    "default_billing": true
                }
            ],
            "disable_auto_group_change": 0,
            "extension_attributes": {
                "company_attributes": {
                    "company_id": 2,
                    "status": 1
                },
                "is_subscribed": false
            }
        }
    ],
    "search_criteria": {
        "filter_groups": [
            {
                "filters": [
                    {
                        "field": "email",
                        "value": "rakesh@jesadiya.com",
                        "condition_type": "eq"
                    }
                ]
            }
        ]
    },
    "total_count": 1
}

Using this way, you can able to search any customer-related field to fetch the result with the help of REST API.

You can pass multiple fields with a single call based on your requirements.