Update javascript client sample program and Vale rules (#6435)
Signed-off-by: Fanit Kolchina <kolchfa@amazon.com>
This commit is contained in:
parent
53d986d7c2
commit
0856c622bf
|
@ -5,5 +5,4 @@ nonword: true
|
|||
scope: raw
|
||||
tokens:
|
||||
- '\]\({2,}[^)]*?\){1,}'
|
||||
- '\]\([^]]*?\){2,}'
|
||||
|
||||
|
|
@ -4,4 +4,4 @@ level: error
|
|||
nonword: true
|
||||
scope: raw
|
||||
tokens:
|
||||
- '\(\{\{site.url\}\}\{\{site.baseurl\}\}.*\/{2,}.*\)'
|
||||
- '\(\{\{site.url\}\}\{\{site.baseurl\}\}[^)]*?\/{2,}[^)]*?\)'
|
||||
|
|
|
@ -17,7 +17,7 @@ You can use helper methods to simplify the use of complicated API tasks. For mor
|
|||
|
||||
## Setup
|
||||
|
||||
To add the client to your project, install it from [npm](https://www.npmjs.com):
|
||||
To add the client to your project, install it from [`npm`](https://www.npmjs.com):
|
||||
|
||||
```bash
|
||||
npm install @opensearch-project/opensearch
|
||||
|
@ -31,7 +31,7 @@ npm install @opensearch-project/opensearch@<version>
|
|||
```
|
||||
{% include copy.html %}
|
||||
|
||||
If you prefer to add the client manually or just want to examine the source code, see [opensearch-js](https://github.com/opensearch-project/opensearch-js) on GitHub.
|
||||
If you prefer to add the client manually or only want to examine the source code, see [`opensearch-js`](https://github.com/opensearch-project/opensearch-js) on GitHub.
|
||||
|
||||
Then require the client:
|
||||
|
||||
|
@ -71,7 +71,22 @@ var client = new Client({
|
|||
```
|
||||
{% include copy.html %}
|
||||
|
||||
## Authenticating with Amazon OpenSearch Service – AWS Sigv4
|
||||
If you are not using the Security plugin, create a client object with the address `http://localhost:9200`:
|
||||
|
||||
```javascript
|
||||
var host = "localhost";
|
||||
var protocol = "http";
|
||||
var port = 9200;
|
||||
|
||||
// Create a client
|
||||
var { Client } = require("@opensearch-project/opensearch");
|
||||
var client = new Client({
|
||||
node: protocol + "://" + host + ":" + port
|
||||
});
|
||||
```
|
||||
{% include copy.html %}
|
||||
|
||||
## Authenticating with Amazon OpenSearch Service: AWS Signature Version 4
|
||||
|
||||
Use the following code to authenticate with AWS V2 SDK:
|
||||
|
||||
|
@ -345,7 +360,23 @@ var response = await client.update({
|
|||
}
|
||||
});
|
||||
```
|
||||
{% include copy.html %}
|
||||
|
||||
For example, the following code updates the `genre` field and adds a `tv_adapted` field to the document specified by `id`:
|
||||
|
||||
```javascript
|
||||
var response = await client.update({
|
||||
index: index_name,
|
||||
id: id,
|
||||
body: {
|
||||
doc: {
|
||||
genre: "Detective fiction",
|
||||
tv_adapted: true
|
||||
}
|
||||
},
|
||||
refresh: true
|
||||
});
|
||||
```
|
||||
{% include copy.html %}
|
||||
|
||||
## Deleting a document
|
||||
|
@ -384,11 +415,11 @@ var port = 9200;
|
|||
var auth = "admin:<custom-admin-password>"; // For testing only. Don't store credentials in code.
|
||||
var ca_certs_path = "/full/path/to/root-ca.pem";
|
||||
|
||||
// Optional client certificates if you don't want to use HTTP basic authentication.
|
||||
// Optional client certificates if you don't want to use HTTP basic authentication
|
||||
// var client_cert_path = '/full/path/to/client.pem'
|
||||
// var client_key_path = '/full/path/to/client-key.pem'
|
||||
|
||||
// Create a client with SSL/TLS enabled.
|
||||
// Create a client with SSL/TLS enabled
|
||||
var { Client } = require("@opensearch-project/opensearch");
|
||||
var fs = require("fs");
|
||||
var client = new Client({
|
||||
|
@ -403,7 +434,7 @@ var client = new Client({
|
|||
});
|
||||
|
||||
async function search() {
|
||||
// Create an index with non-default settings.
|
||||
// Create an index with non-default settings
|
||||
var index_name = "books";
|
||||
|
||||
var settings = {
|
||||
|
@ -423,7 +454,7 @@ async function search() {
|
|||
console.log("Creating index:");
|
||||
console.log(response.body);
|
||||
|
||||
// Add a document to the index.
|
||||
// Add a document to the index
|
||||
var document = {
|
||||
title: "The Outsider",
|
||||
author: "Stephen King",
|
||||
|
@ -443,7 +474,7 @@ async function search() {
|
|||
console.log("Adding document:");
|
||||
console.log(response.body);
|
||||
|
||||
// Search for the document.
|
||||
// Search for the document
|
||||
var query = {
|
||||
query: {
|
||||
match: {
|
||||
|
@ -460,9 +491,41 @@ async function search() {
|
|||
});
|
||||
|
||||
console.log("Search results:");
|
||||
console.log(response.body.hits);
|
||||
console.log(JSON.stringify(response.body.hits, null, " "));
|
||||
|
||||
// Delete the document.
|
||||
// Update a document
|
||||
var response = await client.update({
|
||||
index: index_name,
|
||||
id: id,
|
||||
body: {
|
||||
doc: {
|
||||
genre: "Detective fiction",
|
||||
tv_adapted: true
|
||||
}
|
||||
},
|
||||
refresh: true
|
||||
});
|
||||
|
||||
// Search for the updated document
|
||||
var query = {
|
||||
query: {
|
||||
match: {
|
||||
title: {
|
||||
query: "The Outsider",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
var response = await client.search({
|
||||
index: index_name,
|
||||
body: query,
|
||||
});
|
||||
|
||||
console.log("Search results:");
|
||||
console.log(JSON.stringify(response.body.hits, null, " "));
|
||||
|
||||
// Delete the document
|
||||
var response = await client.delete({
|
||||
index: index_name,
|
||||
id: id,
|
||||
|
@ -471,7 +534,7 @@ async function search() {
|
|||
console.log("Deleting document:");
|
||||
console.log(response.body);
|
||||
|
||||
// Delete the index.
|
||||
// Delete the index
|
||||
var response = await client.indices.delete({
|
||||
index: index_name,
|
||||
});
|
||||
|
@ -483,6 +546,7 @@ async function search() {
|
|||
search().catch(console.log);
|
||||
```
|
||||
{% include copy.html %}
|
||||
|
||||
## Circuit breaker
|
||||
|
||||
The `memoryCircuitBreaker` option can be used to prevent errors caused by a response payload being too large to fit into the heap memory available to the client.
|
||||
|
|
|
@ -8,7 +8,7 @@ redirect_from:
|
|||
|
||||
# Term-level and full-text queries compared
|
||||
|
||||
You can use both term-level and full-text queries to search text, but while term-level queries are usually used to search structured data, full-text queries are used for full-text search. The main difference between term-level and full-text queries is that term-level queries search documents for an exact specified term, while full-text queries [analyze]({{{site.url}}{{site.baseurl}}/analyzers/) the query string. The following table summarizes the differences between term-level and full-text queries.
|
||||
You can use both term-level and full-text queries to search text, but while term-level queries are usually used to search structured data, full-text queries are used for full-text search. The main difference between term-level and full-text queries is that term-level queries search documents for an exact specified term, while full-text queries [analyze]({{site.url}}{{site.baseurl}}/analyzers/) the query string. The following table summarizes the differences between term-level and full-text queries.
|
||||
|
||||
| | Term-level queries | Full-text queries
|
||||
:--- | :--- | :---
|
||||
|
|
Loading…
Reference in New Issue