2016-07-20 113 views
0

我正在使用ES php库。这是我已经尝试过...ElasticSearch索引文档在现有索引上失败

$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); 

这将引发错误和不工作,但它的工作原理,如果我尝试这种无需先创建索引和映射。

请建议。谢谢

回答

0

在'integer'类型的字段中定义分析器是错误的。

力图打造通过Elasticsearch-PHP这个映射给了我一个错误的请求:

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

尝试通过PUT到ES直接创建这个映射给了我同样的错误

我使用的是ES版2.2.0和Elasticsearch-PHP 2.0

+0

如果我从类别中删除分析器,仍然会出现相同的错误。 – seoppc