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

时间:2019-03-03 10:11:19

标签: php laravel elasticsearch

我尝试使用https://github.com/cviebrock/laravel-elasticsearch来设置我的elasticsearch文档,但是我无法为我的某些字段-(Elasticsearch doc)来设置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',
]);

1 个答案:

答案 0 :(得分:0)

我通过使用putMapping()方法解决了此问题。这种方法使我可以定义映射。

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