我使用OpenSearch docker镜像在本地服务器上设置了一个ElasticSearch示例。
$ 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.
我还尝试了最新的ElasticSearch客户端,但它给了我一个连接错误。
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)
})
非常感谢你的帮助。
谢谢
1条答案
按热度按时间w1e3prcc1#
您的Elasticsearch客户端版本比Opensearch分叉的版本7.10.2更新。
您应该将客户端库降级到符合7.10.2,或者使用Opensearch Javascript client。