elasticsearch,Php,Laravel,elasticsearch" /> elasticsearch,Php,Laravel,elasticsearch" />

Php 在cviebrock/laravel elasticsearch中设置elasticsearch映射

Php 在cviebrock/laravel elasticsearch中设置elasticsearch映射,php,laravel,elasticsearch,Php,Laravel,elasticsearch,我尝试使用设置elasticsearch文档,但无法为我的某些字段设置fielddata=true-() 我试过这样做: $elasticSearch = ClientBuilder::create()->build(); $elasticSearch->index([ 'body' => [ 'testField' => 'abc' ], "mappings" => [ '_doc' => [

我尝试使用设置elasticsearch文档,但无法为我的某些字段设置
fielddata=true
-()

我试过这样做:

$elasticSearch = ClientBuilder::create()->build();
$elasticSearch->index([
    'body' => [
        'testField' => 'abc'
    ],
    "mappings" => [
        '_doc' => [
            "properties" => [
                'testField' => [
                    "type" => "text",
                    "fielddata" => true
                ]
            ]
        ]
    ],
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id',
]);

我通过使用
putMapping()
方法解决了这个问题。此方法允许我定义映射

//put mapping
$elasticSearch->indices()->putMapping([
    'index' => 'book',
    'type' => 'books',
    'body' => [
        "properties" => [
            'name' => [
                "type" => "text",
                "fielddata" => true
            ],
            'author_name' => [
                "type" => "text",
                "fielddata" => true
            ]
        ]
    ]
]);