搜索错误:[index_not_found_exception]在elasticsearch中没有这样的索引

时间:2017-02-15 12:58:02

标签: node.js elasticsearch

第一次运行创建索引的代码时,我有索引未找到异常,但第二次它运行良好。

这是我的代码

function searchIndex(callback){

    client.search({  
        index: 'postgrescredentials-01',
        type: 'credentials',
        body: {
            query: {
                match: { 
                    "username": "postgres" 
                }
            },
        }
    },function (error, response,status) {

        if (error){
            console.log("search error: "+error)
        }
        else { 
            response.hits.hits.forEach(function(hit){
                var ciphertext = hit._source.pswrd
                callback(ciphertext)
            })
        }

    });
};

exports.searchIndex = searchIndex;
encryptObj = enpyt.encrypt(password,function(encrypted){

    client.index({  
        index: 'postgrescredentials-01',
        id: '101',
        type: 'credentials',
            body: {
            "username": "postgres",
            "pswrd": encrypted

            }
    },function(err,resp,status) {
            console.log(resp);
    });
    console.log("The encrypted password is-->",encrypted)       
    //Get The Searched Encrypted value 
    search.searchIndex(function(encryptedValue){        
        //Get the Decrypted Value
        decrypt.decrypt(encryptedValue,function(decryptedValue){        
            console.log("The decrypted password is-->",decryptedValue); 
        });
    });
    })

我知道为什么我在第一次执行时遇到索引未找到异常。

0 个答案:

没有答案