Elasticsearch 错误 "The client noticed that the server is not Elasticsearch and we do not support this unknown product"

Elasticsearch error "The client noticed that the server is not Elasticsearch and we do not support this unknown product"

我使用 OpenSearch docker 图像在我的本地服务器中设置了一个弹性搜索实例。

$ docker run -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" opensearchproject/opensearch:1.3.1

我可以看到实例已启动 运行 https://localhost:9200/

尝试执行简单搜索时出现以下错误。

ProductNotSupportedError: The client noticed that the server is not Elasticsearch and we do not support this unknown product.

我也尝试了最新的弹性搜索客户端,但它给我一个连接错误。

   error ConnectionError: unable to verify the first certificate

代码示例:

//const { Client } = require('@elastic/elasticsearch') // Got connection error when using latest version 
const {Client: Client} = require('es7')
var connectionString = 'https://admin:admin@localhost:9200'
const client = new Client({
    node: connectionString,
    ssl: {
        rejectUnauthorized: false
    }
})
client.info()
    .then(async response => {
        console.log('success', response.statusCode);
        const result = await client.search({
            index: 'r7',
            query: {
                match: {
                    subtype: 'a'
                }
            }
        })
        console.log('result', result)
        console.log('count', result.hits.hits)
    })
    .catch(error => {
        console.error('error', error)
    })

非常感谢您的帮助。

谢谢。

您的 Elasticsearch 客户端版本高于 7.10.2,即 Opensearch 的分支版本。

您应该降级客户端库以匹配 7.10.2,或者改用 Opensearch Javascript client