D
D
dark_spectator2019-04-22 22:21:51
PHP
dark_spectator, 2019-04-22 22:21:51

ElasticSearch throws an error when adding a new type?

I am creating a web service using ElasticSearch as the main data store.
There is a registration method, when a request arrives at it, it creates a new user, it goes with a bang, but when creating a type for storing records about the user's friends, an error occurs.
user.php:

$client = ClientBuilder::create()->build();
        $user = array(
            "login"             => $login,
            "email"             => $email,
            "avatar_url"        => $avatar_url,
            "password"          => $password,
            "email_verify"      => false,
            "email_verify_id"   => $email_verify_id,
            "user_token"        => $user_token,
            "g-balance"         => 0,
            "register_time"     => time(),
            "last_query_time"   => time(),
            "receive_bonuses"   => 0,
            "total_playtime"    => 0,
            "games"             => array(
                $game_name  => array(
                    "playtime"  => 0,
                    "level"     => 0,
                    "save"      => "",
                ),
            ),
        );
        $params = array(
            "index" => "socket-apps-db",
            "type"  => "users",
            "id"    =>  mb_strtolower($login),
            "body"  => $user
        );
        $database_response = $client->index($params);
        if($database_response["result"] == "created"){
            return array(
              "status"  => true,
            );
        }else{
            return array(
                "status"  => false,
            );
        }

UserFriends.php:
$client = ClientBuilder::create()->build();
        $params = array(
            "index" => "socket-apps-friends",
            "type"  => mb_strtolower($login),
            "body" => array(),
        );
        $client->index($params);

When requesting the API of the first user, it inserts, creates all the indexes, everything is fine, but it answers the second registration:
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [socket-apps-friends] as the final mapping would have more than 1 type: [socketsystem, hoo]"}],"type":"illegal_argument_exception","reason":"Rejecting mapping update to [socket-apps-friends] as the final mapping would have more than 1 type: [socketsystem, hoo]"},"status":400}

It's related to mapping, but I don't know how to solve this problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2019-04-22
@dark_spectator

Elastic writes to you that there can be only one type per index!
Here it is
Replace with
And hide the user in the field in the bodysuit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question