简体   繁体   中英

ElasticSearch Index a Document fails on existing index

I am using ES php library. Here is what i have tried...

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

It returns success.

Now when i try to index a document...

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

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

This throws error and does not work, however it works If i try this without creating index and mapping first.

Please suggest. Thanks

It's wrong to define analyzer in a field of type 'integer'.

Trying to create this mapping through Elasticsearch-PHP gives me a bad request:

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

Trying to create this mapping directly via PUT to ES gives me same error

I'm using ES version 2.2.0 and Elasticsearch-PHP 2.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM