opensearch-docs-cn/_clients/index.md

104 lines
3.5 KiB
Markdown
Raw Normal View History

---
layout: default
title: Language clients
nav_order: 1
has_children: false
redirect_from:
- /clients/
---
# OpenSearch language clients
OpenSearch provides clients for several popular programming languages, with more to come.
## OpenSearch language client compatibility
In general, clients are compatible with clusters running the same major version of OpenSearch (`major.minor.patch`).
For example, a 1.0.0 client works with an OpenSearch 1.1.0 cluster, but might not support any non-breaking API changes in OpenSearch 1.1.0. A 1.2.0 client works with the same cluster, but might allow you to pass unsupported options in certain functions. We recommend using the same version for both, but if your tests pass after a cluster upgrade, you don't necessarily need to upgrade your clients immediately.
2021-09-30 16:48:32 -04:00
{% comment %}
* [OpenSearch Java client]({{site.url}}{{site.baseurl}}/clients/java/)
2021-09-30 16:48:32 -04:00
{% endcomment %}
* [OpenSearch Python client]({{site.url}}{{site.baseurl}}/clients/python-low-level/)
* [OpenSearch JavaScript (Node.js) client]({{site.url}}{{site.baseurl}}/clients/javascript/index)
* [OpenSearch .NET clients]({{site.url}}{{site.baseurl}}/clients/dot-net/)
2021-09-21 16:56:25 -04:00
* [OpenSearch Go client]({{site.url}}{{site.baseurl}}/clients/go/)
* [OpenSearch PHP client]({{site.url}}{{site.baseurl}}/clients/php/)
## Legacy clients
Most clients that work with Elasticsearch OSS 7.10.2 *should* work with OpenSearch, but the latest versions of those clients might include license or version checks that artificially break compatibility. This page includes recommendations around which versions of those clients to use for best compatibility with OpenSearch.
Client | Recommended version
:--- | :---
2021-08-10 15:00:12 -04:00
[Java low-level REST client](https://search.maven.org/artifact/org.elasticsearch.client/elasticsearch-rest-client/7.13.4/jar) | 7.13.4
[Java high-level REST client](https://search.maven.org/artifact/org.elasticsearch.client/elasticsearch-rest-high-level-client/7.13.4/jar) | 7.13.4
[Python Elasticsearch client](https://pypi.org/project/elasticsearch/7.13.4/) | 7.13.4
[Elasticsearch Node.js client](https://www.npmjs.com/package/@elastic/elasticsearch/v/7.13.0) | 7.13.0
2021-11-11 12:33:23 -05:00
[Ruby Elasticsearch client](https://rubygems.org/gems/elasticsearch/versions/7.13.0) | 7.13.0
If you test a legacy client and verify that it works, please [submit a PR](https://github.com/opensearch-project/documentation-website/pulls) and add it to this table.
2021-07-26 12:59:48 -04:00
{% comment %}
## Python 3 test code
This code indexes a single document and is equivalent to `PUT /python-test-index1/_doc/1`.
```python
from elasticsearch import Elasticsearch
host = 'localhost'
port = 9200
# For testing only. Do not store credentials in code.
auth = ('admin', 'admin')
es = Elasticsearch(
hosts = [{'host': host, 'port': port}],
http_auth = auth,
use_ssl = True,
verify_certs = False
)
document = {
"title": "Moneyball",
"director": "Bennett Miller",
"year": "2011"
}
response = es.index(index='python-test-index1', id='1', body=document, refresh=True)
print(response)
```
## Node.js test code
This code is equivalent to `GET /`.
```js
const { Client } = require('@elastic/elasticsearch')
const client = new Client({
node: 'https://localhost:9200',
auth: {
// For testing only. Don't store credentials in code.
username: 'admin',
password: 'admin'
},
ssl: {
// ca: fs.readFileSync('./cacert.pem'),
rejectUnauthorized: false
}
})
async function run () {
const { body } = await client.info();
console.log(body);
}
run().catch(console.log)
```
{% endcomment %}