ElasticSearch索引文档在现有索引上失败

时间:2016-07-20 22:12:03

标签: php elasticsearch

我正在使用ES php库。这是我试过的......

$params = [
    'index' => 'tasks',
    'body' => [
        'settings' => [
            'number_of_shards' => 3,
            'number_of_replicas' => 2
        ],
        'mappings' => [
            'all' => [
                '_source' => [
                    'enabled' => true
                ],
                'properties' => [
                    'task' => [
                        'type' => 'string',
                        'analyzer' => 'standard'
                    ],
                    'to' => [
                        'type' => 'string',
                        'analyzer' => 'standard'
                    ],
                    'category' => [
                        'type' => 'integer',
                        'analyzer' => 'keyword'
                    ]
                ]
            ]
        ]
    ]
];

// Create the index with mappings and settings now
$response = $client->indices()->create($params);

它返回成功。

现在,当我尝试索引文档时......

$params = [
    'index' => 'tasks',
    'type' => 'all',
    'id' => 'some_id',
    'body' => [ 'task' => 'some test', 'to' => 'name', 'category' => 1]
];

$response = $client->index($params);

这会引发错误并且不起作用,但是它可以工作如果我尝试这个而不先创建索引和映射。

请建议。感谢

1 个答案:

答案 0 :(得分:0)

在“整数”类型的字段中定义分析器是错误的。

尝试通过Elasticsearch-PHP创建此映射给我一个错误的请求:

... "reason":"Mapping definition for [category] has unsupported parameters:  [analyzer : keyword]"}},"status":400}

尝试通过PUT直接创建此映射给我同样的错误

我正在使用ES 2.2.0版和Elasticsearch-PHP 2.0