私はElasticサーバー(バージョン2.3.1)を稼働しており、公式のPHP clientを使用して文書を保存しようとしています。PHP Elasticsearch "Set"マッピング
$data = Array(
"index"=> "my_index",
"type" => "my_type",
"id" => $my_generated_id,
"body" => Array(
"name" => $name,
"other_field" => $other_data,
"tags" => array_unique($tags)
)
);
ますprint_r($データ):構造IはPHP
で作成する最初の文書がきれいに保存されている
Array
(
[index] => my_index
[type] => my_type
[id] => AFCDEFGH
[body] => Array
(
[name] => It is my name
[other_field] => some other information
[tags] => Array
(
[0] => Some tag
[2] => Some other tag
)
)
)
を(そしてそれは、インデックスが作成されます)とすぐに私は挿入しようとしてではなく私はいくつかのエラーを取得するタグの数が異なる文書:
PHP Fatal error: Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception: {"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"object mapping for [tags] tried to parse field [null] as object, but found a concrete value"}],"type":"mapper_parsing_exception","reason":"object mapping for [tags] tried to parse field [null] as object, but found a concrete value"},"status":400} in /home/test/test/php/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:655
私はインデックスが間違った方法で構築されていることを知っている:
{
"my_index":{
"aliases":{
},
"mappings":{
"targy":{
"properties":{
"other_field":{
"type":"string"
},
"name":{
"type":"string"
},
"tags":{
"properties":{
"0":{
"type":"string"
},
"2":{
"type":"string"
}
}
}
}
}
},
"settings":{
"index":{
"creation_date":"1477414478664",
"number_of_shards":"5",
"number_of_replicas":"1",
"uuid":"yZiN4uUgRXe9vyaN4uWbGg",
"version":{
"created":"2030199"
}
}
},
"warmers":{
}
}
}
PHP
のマッピングを手動で作成して、同時に0個以上のタグを処理できるようにするにはどうすればよいですか? (私は解決策がarray
としてではなく、私は過去数日間を探していたいくつかの他のデータ型のstrings
のこの「袋」を処理するためにはないと思う。)
例:後
[tags] => Array
(
[0] => Some tag
[2] => Some other tag
[3] => Some other tag
)
//...
[tags] => Array
(
)
は、あなたの答えをありがとうしかし、この方法は、私は、文書の空または例えば6タグを保存することができるのだろうか?私はさまざまな数のタグを持っていますが、どれくらいのものが表現されるかを判断することはできません。 – Mark
はい、配列のサイズに制限はなく、マッピングは '" tags ":{type:" string "}'のままです。文字列と同じです。 – Pandawan