elasticsearch索引异常

elasticsearch索引异常

本文介绍了未找到putMapping elasticsearch索引异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是尝试使用putMapping创建索引,并且可以肯定这是一个语法问题.弹性客户端正在处理.index和.search命令,因此我不认为这是问题所在.确切地说,这与我的贴图代码有关.任何建议将不胜感激.关于我要做什么的一些描述.我搜索了一个索引,发现它不存在.我捕获了错误并进行测试,看是否等于"index_not_found_exception".如果是这样,我需要创建索引."..."之下的所有内容都位于.catch内部.

I am just trying to create an index using putMapping and am fairly certain this is a syntax issue. The elastic client is working for .index and .search commands, so I do not believe the setup of it is the issue. Rather it is something with my putmapping code. Any suggestions would be much appreciated. A little description of what I am trying to do. I have searched an index, and found that it does not exist. I catch the error and test to see if it equals "index_not_found_exception". If so, I need to create the index. Everything below the "..." is inside the .catch.

"use strict";
let config = require("./config"),
    soap = require("soap"),
    elastic = require("elasticsearch").Client(config.routeHost);
...
 if (error.body.error.type == "index_not_found_exception") {
        console.log("no index");
        elastic.indices.putMapping({
            index: "ppvevents",
            type: "ppvObject",
            body: {
                properties: {
                    name: {type: "string", index: "not_analyzed"},
                    hdid: {type: "integer"},
                    sdid: {type: "integer"}
                }
            }
        }).then(function(response){
            console.log("Response: ", response);
        }).catch(function(error){
            console.log("putMapping Error: ", error);
        });
    } else if(error.body.error.type != "index_not_found_exception") {
        console.log("error: elasticsearch client search");
        console.log(error);
    }

控制台响应如下:

vagrant at localhost in /vagrant on master!
± node index.js
9000
no index
putMapping Error:  { [Error: [index_not_found_exception] no such index, with { resource.type=index_or_alias resource.id=ppvevents index=ppvevents }]
    status: 404,
    displayName: 'NotFound',
    message: '[index_not_found_exception] no such index, with { resource.type=index_or_alias resource.id=ppvevents index=ppvevents }',
    path: '/ppvevents/_mapping/ppvObject',
    query: {},
    body:
        { error:
            { root_cause: [Object],
                type: 'index_not_found_exception',
                reason: 'no such index',
                'resource.type': 'index_or_alias',
                'resource.id': 'ppvevents',
                index: 'ppvevents' },
            status: 404 },
        statusCode: 404,
        response: '{"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"ppvevents","index":"ppvevents"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"ppvevents","index":"ppvevents"},"status":404}',
toString: [Function],
toJSON: [Function] }

推荐答案

如果索引不存在, putMapping()将无济于事,您需要致电 indices.create . putMapping 只能用于向现有索引添加新的映射类型.

If the index does not exist, putMapping() won't help, you need to call indices.create instead. putMapping can only be used to add a new mapping type to an already existing index.

将此替换为putMapping调用:

Replace your putMapping call with this:

    elastic.indices.createIndex({
        index: "ppvevents",
        body: {
            mappings: {
               ppvObject: {
                  properties: {
                     name: {type: "string", index: "not_analyzed"},
                     hdid: {type: "integer"},
                     sdid: {type: "integer"}
                  }
               }
            }
        }

这篇关于未找到putMapping elasticsearch索引异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 06:03