Update docs to use async/await (#667)
* [docs] update readme and examples to use async/await * [apis] regenerate (including updated examples)
This commit is contained in:
27
README.md
27
README.md
@ -70,18 +70,19 @@ client.ping({
|
||||
|
||||
Skip the callback to get a promise back
|
||||
```js
|
||||
client.search({
|
||||
q: 'pants'
|
||||
}).then(function (body) {
|
||||
var hits = body.hits.hits;
|
||||
}, function (error) {
|
||||
console.trace(error.message);
|
||||
});
|
||||
try {
|
||||
const response = await client.search({
|
||||
q: 'pants'
|
||||
});
|
||||
console.log(response.hits.hits)
|
||||
} catch (error) {
|
||||
console.trace(error.message)
|
||||
}
|
||||
```
|
||||
|
||||
Find tweets that have "elasticsearch" in their body field
|
||||
```js
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'twitter',
|
||||
type: 'tweets',
|
||||
body: {
|
||||
@ -91,11 +92,11 @@ client.search({
|
||||
}
|
||||
}
|
||||
}
|
||||
}).then(function (resp) {
|
||||
var hits = resp.hits.hits;
|
||||
}, function (err) {
|
||||
console.trace(err.message);
|
||||
});
|
||||
})
|
||||
|
||||
for (const tweet of response.hits.hits) {
|
||||
console.log('tweet:', tweet);
|
||||
}
|
||||
```
|
||||
|
||||
More examples and detailed information about each method are available [here](http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html)
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
.Return information about JVM
|
||||
[source,js]
|
||||
---------
|
||||
client.cluster.nodeInfo({ jvm: true })
|
||||
.then(function (response) {
|
||||
// enjoy your sweet info!
|
||||
}, function (error) {
|
||||
// scream!
|
||||
})
|
||||
---------
|
||||
const response = await client.cluster.nodeInfo({
|
||||
jvm: true
|
||||
});
|
||||
---------
|
||||
|
||||
@ -1,26 +1,21 @@
|
||||
.Get the number of all documents in the cluster
|
||||
[source,js]
|
||||
---------
|
||||
client.count(function (error, response, status) {
|
||||
// check for and handle error
|
||||
var count = response.count;
|
||||
});
|
||||
const { count } = await client.count();
|
||||
---------
|
||||
|
||||
.Get the number of documents in an index
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Get the number of documents matching a query
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name',
|
||||
body: {
|
||||
query: {
|
||||
@ -33,7 +28,5 @@ client.count({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (err, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
.Create a document
|
||||
[source,js]
|
||||
---------
|
||||
client.create({
|
||||
await client.create({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -12,7 +12,5 @@ client.create({
|
||||
published_at: '2013-01-01',
|
||||
counter: 1
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
---------
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
.Delete the document `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.delete({
|
||||
await client.delete({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
---------
|
||||
|
||||
@ -1,25 +1,21 @@
|
||||
.Deleting documents with a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'myindex',
|
||||
q: 'test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Deleting documents using the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'posts',
|
||||
body: {
|
||||
query: {
|
||||
term: { published: false }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
---------
|
||||
|
||||
@ -1,15 +1,9 @@
|
||||
.Check that the document `/myindex/mytype/1` exist
|
||||
[source,js]
|
||||
---------
|
||||
client.exists({
|
||||
const exists = await client.exists({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, exists) {
|
||||
if (exists === true) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
});
|
||||
---------
|
||||
---------
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
.See how a document is scored against a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
// the document to test
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
@ -9,15 +9,13 @@ client.explain({
|
||||
|
||||
// the query to score it against
|
||||
q: 'field:value'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.See how a document is scored against a query written in the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -26,7 +24,5 @@ client.explain({
|
||||
match: { title: 'test' }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
---------
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
.Get `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.get({
|
||||
const response = await client.get({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
---------
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
.Create or update a document
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
const response = await client.index({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -10,7 +10,5 @@ client.index({
|
||||
tags: ['y', 'z'],
|
||||
published: true,
|
||||
}
|
||||
}, function (error, response) {
|
||||
|
||||
});
|
||||
---------
|
||||
---------
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
.Perform an atomic alias swap, for a rotating index
|
||||
[source,js]
|
||||
---------
|
||||
client.indices.updateAliases({
|
||||
const response = await client.indices.updateAliases({
|
||||
body: {
|
||||
actions: [
|
||||
{ remove: { index: 'logstash-2014.04', alias: 'logstash-current' } },
|
||||
{ add: { index: 'logstash-2014.05', alias: 'logstash-current' } }
|
||||
]
|
||||
}
|
||||
}).then(function (response) {
|
||||
// ...
|
||||
}, errorHandler);
|
||||
---------
|
||||
});
|
||||
---------
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
.An array of doc locations. Useful for getting documents from different indices.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
body: {
|
||||
docs: [
|
||||
{ _index: 'indexA', _type: 'typeA', _id: '1' },
|
||||
@ -9,21 +9,17 @@ client.mget({
|
||||
{ _index: 'indexC', _type: 'typeC', _id: '1' }
|
||||
]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.An array of ids. You must also specify the `index` and `type` that apply to all of the ids.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
ids: [1, 2, 3]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
---------
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
.Search for similar documents using the `title` property of document `myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.mlt({
|
||||
const response = await client.mlt({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1,
|
||||
mlt_fields: 'title'
|
||||
}, function (errors, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
---------
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
.Perform multiple different searches, the body is made up of meta/data pairs
|
||||
[source,js]
|
||||
---------
|
||||
client.msearch({
|
||||
const response = await client.msearch({
|
||||
body: [
|
||||
// match all query, on all indices and types
|
||||
{},
|
||||
|
||||
@ -1,43 +1,41 @@
|
||||
.First, Register queries named “alert-1” and “alert-2” for the “myindex” index
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
await Promise.all([
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
}),
|
||||
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
})
|
||||
]);
|
||||
---------
|
||||
|
||||
.Then you can send documents to learn which query `_percolator` queries they match
|
||||
[source,js]
|
||||
---------
|
||||
client.percolate({
|
||||
const response1 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -45,15 +43,15 @@ client.percolate({
|
||||
title: "Foo"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
});
|
||||
|
||||
client.percolate({
|
||||
// response1 should look something like
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
|
||||
const response2 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -61,14 +59,14 @@ client.percolate({
|
||||
title: "Foo Bar"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
---------
|
||||
|
||||
// response2 should look something like
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
---------
|
||||
|
||||
@ -1,28 +1,38 @@
|
||||
.Collect every title in the index that contains the word "test"
|
||||
[source,js]
|
||||
---------
|
||||
var allTitles = [];
|
||||
const allTitles = [];
|
||||
const responseQueue = [];
|
||||
|
||||
// first we do a search, and specify a scroll timeout
|
||||
client.search({
|
||||
// start things off by searching, setting a scroll timeout, and pushing
|
||||
// our first response into the queue to be processed
|
||||
await client.search({
|
||||
index: 'myindex',
|
||||
scroll: '30s', // keep the search results "scrollable" for 30 seconds
|
||||
source: ['title'], // filter the source to only include the title field
|
||||
q: 'title:test'
|
||||
}, function getMoreUntilDone(error, response) {
|
||||
// collect the title from each response
|
||||
})
|
||||
|
||||
while (responseQueue.length) {
|
||||
const response = responseQueue.shift();
|
||||
|
||||
// collect the titles from this response
|
||||
response.hits.hits.forEach(function (hit) {
|
||||
allTitles.push(hit._source.title);
|
||||
allTitles.push(hit.fields.title);
|
||||
});
|
||||
|
||||
if (response.hits.total > allTitles.length) {
|
||||
// ask elasticsearch for the next set of hits from this search
|
||||
client.scroll({
|
||||
// check to see if we have collected all of the titles
|
||||
if (response.hits.total === allTitles.length) {
|
||||
console.log('every "test" title', allTitles);
|
||||
break
|
||||
}
|
||||
|
||||
// get the next response if there are more titles to fetch
|
||||
responseQueue.push(
|
||||
await client.scroll({
|
||||
scrollId: response._scroll_id,
|
||||
scroll: '30s'
|
||||
}, getMoreUntilDone);
|
||||
} else {
|
||||
console.log('every "test" title', allTitles);
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
---------
|
||||
|
||||
@ -1,18 +1,16 @@
|
||||
.Search with a simple query string query
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
q: 'title:test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Passing a full request definition in the Elasticsearch's Query DSL as a `Hash`
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
query: {
|
||||
@ -28,7 +26,5 @@ client.search({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
---------
|
||||
|
||||
@ -1,17 +1,18 @@
|
||||
.Return query terms suggestions (“auto-correction”)
|
||||
[source,js]
|
||||
---------
|
||||
client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
const response = await client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
});
|
||||
|
||||
// response will be formatted like so:
|
||||
//
|
||||
// {
|
||||
@ -30,5 +31,5 @@ body: {
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
---------
|
||||
|
||||
---------
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
.Update document title using partial document
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -11,15 +11,13 @@ client.update({
|
||||
title: 'Updated'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Add a tag to document `tags` property using a `script`
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -27,15 +25,13 @@ client.update({
|
||||
script: 'ctx._source.tags += tag',
|
||||
params: { tag: 'some new tag' }
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Increment a document counter by 1 or initialize it, when the document does not exist
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '777',
|
||||
@ -45,15 +41,13 @@ client.update({
|
||||
counter: 1
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Delete a document if it's tagged “to-delete”
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -63,7 +57,5 @@ client.update({
|
||||
tag: 'to-delete'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
---------
|
||||
|
||||
@ -116,26 +116,21 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get the number of all documents in the cluster
|
||||
[source,js]
|
||||
---------
|
||||
client.count(function (error, response, status) {
|
||||
// check for and handle error
|
||||
var count = response.count;
|
||||
});
|
||||
const { count } = await client.count();
|
||||
---------
|
||||
|
||||
.Get the number of documents in an index
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Get the number of documents matching a query
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name',
|
||||
body: {
|
||||
query: {
|
||||
@ -148,8 +143,6 @@ client.count({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (err, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
@ -218,7 +211,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create a document
|
||||
[source,js]
|
||||
---------
|
||||
client.create({
|
||||
await client.create({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -229,12 +222,11 @@ client.create({
|
||||
published_at: '2013-01-01',
|
||||
counter: 1
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -292,16 +284,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Delete the document `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.delete({
|
||||
await client.delete({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -357,30 +348,27 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Deleting documents with a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'myindex',
|
||||
q: 'test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Deleting documents using the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'posts',
|
||||
body: {
|
||||
query: {
|
||||
term: { published: false }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -519,20 +507,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Check that the document `/myindex/mytype/1` exist
|
||||
[source,js]
|
||||
---------
|
||||
client.exists({
|
||||
const exists = await client.exists({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, exists) {
|
||||
if (exists === true) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -645,7 +628,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.See how a document is scored against a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
// the document to test
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
@ -653,15 +636,13 @@ client.explain({
|
||||
|
||||
// the query to score it against
|
||||
q: 'field:value'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.See how a document is scored against a query written in the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -670,12 +651,11 @@ client.explain({
|
||||
match: { title: 'test' }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -774,16 +754,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.get({
|
||||
const response = await client.get({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -921,7 +900,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create or update a document
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
const response = await client.index({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -930,12 +909,11 @@ client.index({
|
||||
tags: ['y', 'z'],
|
||||
published: true,
|
||||
}
|
||||
}, function (error, response) {
|
||||
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1015,7 +993,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.An array of doc locations. Useful for getting documents from different indices.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
body: {
|
||||
docs: [
|
||||
{ _index: 'indexA', _type: 'typeA', _id: '1' },
|
||||
@ -1023,26 +1001,23 @@ client.mget({
|
||||
{ _index: 'indexC', _type: 'typeC', _id: '1' }
|
||||
]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.An array of ids. You must also specify the `index` and `type` that apply to all of the ids.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
ids: [1, 2, 3]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1086,7 +1061,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform multiple different searches, the body is made up of meta/data pairs
|
||||
[source,js]
|
||||
---------
|
||||
client.msearch({
|
||||
const response = await client.msearch({
|
||||
body: [
|
||||
// match all query, on all indices and types
|
||||
{},
|
||||
@ -1401,30 +1376,40 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Collect every title in the index that contains the word "test"
|
||||
[source,js]
|
||||
---------
|
||||
var allTitles = [];
|
||||
const allTitles = [];
|
||||
const responseQueue = [];
|
||||
|
||||
// first we do a search, and specify a scroll timeout
|
||||
client.search({
|
||||
// start things off by searching, setting a scroll timeout, and pushing
|
||||
// our first response into the queue to be processed
|
||||
await client.search({
|
||||
index: 'myindex',
|
||||
scroll: '30s', // keep the search results "scrollable" for 30 seconds
|
||||
source: ['title'], // filter the source to only include the title field
|
||||
q: 'title:test'
|
||||
}, function getMoreUntilDone(error, response) {
|
||||
// collect the title from each response
|
||||
})
|
||||
|
||||
while (responseQueue.length) {
|
||||
const response = responseQueue.shift();
|
||||
|
||||
// collect the titles from this response
|
||||
response.hits.hits.forEach(function (hit) {
|
||||
allTitles.push(hit._source.title);
|
||||
allTitles.push(hit.fields.title);
|
||||
});
|
||||
|
||||
if (response.hits.total > allTitles.length) {
|
||||
// ask elasticsearch for the next set of hits from this search
|
||||
client.scroll({
|
||||
// check to see if we have collected all of the titles
|
||||
if (response.hits.total === allTitles.length) {
|
||||
console.log('every "test" title', allTitles);
|
||||
break
|
||||
}
|
||||
|
||||
// get the next response if there are more titles to fetch
|
||||
responseQueue.push(
|
||||
await client.scroll({
|
||||
scrollId: response._scroll_id,
|
||||
scroll: '30s'
|
||||
}, getMoreUntilDone);
|
||||
} else {
|
||||
console.log('every "test" title', allTitles);
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
---------
|
||||
|
||||
|
||||
@ -1460,18 +1445,16 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Search with a simple query string query
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
q: 'title:test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Passing a full request definition in the Elasticsearch's Query DSL as a `Hash`
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
query: {
|
||||
@ -1487,12 +1470,11 @@ client.search({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1777,7 +1759,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Update document title using partial document
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -1787,15 +1769,13 @@ client.update({
|
||||
title: 'Updated'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Add a tag to document `tags` property using a `script`
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -1803,15 +1783,13 @@ client.update({
|
||||
script: 'ctx._source.tags += tag',
|
||||
params: { tag: 'some new tag' }
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Increment a document counter by 1 or initialize it, when the document does not exist
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '777',
|
||||
@ -1821,15 +1799,13 @@ client.update({
|
||||
counter: 1
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Delete a document if it's tagged “to-delete”
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -1839,12 +1815,11 @@ client.update({
|
||||
tag: 'to-delete'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -4419,19 +4394,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform an atomic alias swap, for a rotating index
|
||||
[source,js]
|
||||
---------
|
||||
client.indices.updateAliases({
|
||||
const response = await client.indices.updateAliases({
|
||||
body: {
|
||||
actions: [
|
||||
{ remove: { index: 'logstash-2014.04', alias: 'logstash-current' } },
|
||||
{ add: { index: 'logstash-2014.05', alias: 'logstash-current' } }
|
||||
]
|
||||
}
|
||||
}).then(function (response) {
|
||||
// ...
|
||||
}, errorHandler);
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
|
||||
@ -109,26 +109,21 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get the number of all documents in the cluster
|
||||
[source,js]
|
||||
---------
|
||||
client.count(function (error, response, status) {
|
||||
// check for and handle error
|
||||
var count = response.count;
|
||||
});
|
||||
const { count } = await client.count();
|
||||
---------
|
||||
|
||||
.Get the number of documents in an index
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Get the number of documents matching a query
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name',
|
||||
body: {
|
||||
query: {
|
||||
@ -141,8 +136,6 @@ client.count({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (err, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
@ -189,7 +182,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create a document
|
||||
[source,js]
|
||||
---------
|
||||
client.create({
|
||||
await client.create({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -200,12 +193,11 @@ client.create({
|
||||
published_at: '2013-01-01',
|
||||
counter: 1
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -270,16 +262,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Delete the document `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.delete({
|
||||
await client.delete({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -338,30 +329,27 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Deleting documents with a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'myindex',
|
||||
q: 'test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Deleting documents using the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'posts',
|
||||
body: {
|
||||
query: {
|
||||
term: { published: false }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -426,20 +414,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Check that the document `/myindex/mytype/1` exist
|
||||
[source,js]
|
||||
---------
|
||||
client.exists({
|
||||
const exists = await client.exists({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, exists) {
|
||||
if (exists === true) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -479,7 +462,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.See how a document is scored against a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
// the document to test
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
@ -487,15 +470,13 @@ client.explain({
|
||||
|
||||
// the query to score it against
|
||||
q: 'field:value'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.See how a document is scored against a query written in the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -504,12 +485,11 @@ client.explain({
|
||||
match: { title: 'test' }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -573,16 +553,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.get({
|
||||
const response = await client.get({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -685,7 +664,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create or update a document
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
const response = await client.index({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -694,12 +673,11 @@ client.index({
|
||||
tags: ['y', 'z'],
|
||||
published: true,
|
||||
}
|
||||
}, function (error, response) {
|
||||
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -786,7 +764,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.An array of doc locations. Useful for getting documents from different indices.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
body: {
|
||||
docs: [
|
||||
{ _index: 'indexA', _type: 'typeA', _id: '1' },
|
||||
@ -794,26 +772,23 @@ client.mget({
|
||||
{ _index: 'indexC', _type: 'typeC', _id: '1' }
|
||||
]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.An array of ids. You must also specify the `index` and `type` that apply to all of the ids.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
ids: [1, 2, 3]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -855,17 +830,16 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Search for similar documents using the `title` property of document `myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.mlt({
|
||||
const response = await client.mlt({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1,
|
||||
mlt_fields: 'title'
|
||||
}, function (errors, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -933,7 +907,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform multiple different searches, the body is made up of meta/data pairs
|
||||
[source,js]
|
||||
---------
|
||||
client.msearch({
|
||||
const response = await client.msearch({
|
||||
body: [
|
||||
// match all query, on all indices and types
|
||||
{},
|
||||
@ -985,43 +959,41 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.First, Register queries named “alert-1” and “alert-2” for the “myindex” index
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
await Promise.all([
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
}),
|
||||
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
})
|
||||
]);
|
||||
---------
|
||||
|
||||
.Then you can send documents to learn which query `_percolator` queries they match
|
||||
[source,js]
|
||||
---------
|
||||
client.percolate({
|
||||
const response1 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1029,15 +1001,15 @@ client.percolate({
|
||||
title: "Foo"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
});
|
||||
|
||||
client.percolate({
|
||||
// response1 should look something like
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
|
||||
const response2 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1045,19 +1017,20 @@ client.percolate({
|
||||
title: "Foo Bar"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
// response2 should look something like
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1163,18 +1136,16 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Search with a simple query string query
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
q: 'title:test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Passing a full request definition in the Elasticsearch's Query DSL as a `Hash`
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
query: {
|
||||
@ -1190,12 +1161,11 @@ client.search({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1302,17 +1272,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Return query terms suggestions (“auto-correction”)
|
||||
[source,js]
|
||||
---------
|
||||
client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
const response = await client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
});
|
||||
|
||||
// response will be formatted like so:
|
||||
//
|
||||
// {
|
||||
@ -1331,10 +1302,11 @@ body: {
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1375,7 +1347,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Update document title using partial document
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -1385,15 +1357,13 @@ client.update({
|
||||
title: 'Updated'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Add a tag to document `tags` property using a `script`
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -1401,15 +1371,13 @@ client.update({
|
||||
script: 'ctx._source.tags += tag',
|
||||
params: { tag: 'some new tag' }
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Increment a document counter by 1 or initialize it, when the document does not exist
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '777',
|
||||
@ -1419,15 +1387,13 @@ client.update({
|
||||
counter: 1
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Delete a document if it's tagged “to-delete”
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -1437,12 +1403,11 @@ client.update({
|
||||
tag: 'to-delete'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1628,15 +1593,13 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Return information about JVM
|
||||
[source,js]
|
||||
---------
|
||||
client.cluster.nodeInfo({ jvm: true })
|
||||
.then(function (response) {
|
||||
// enjoy your sweet info!
|
||||
}, function (error) {
|
||||
// scream!
|
||||
})
|
||||
const response = await client.cluster.nodeInfo({
|
||||
jvm: true
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -2952,19 +2915,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform an atomic alias swap, for a rotating index
|
||||
[source,js]
|
||||
---------
|
||||
client.indices.updateAliases({
|
||||
const response = await client.indices.updateAliases({
|
||||
body: {
|
||||
actions: [
|
||||
{ remove: { index: 'logstash-2014.04', alias: 'logstash-current' } },
|
||||
{ add: { index: 'logstash-2014.05', alias: 'logstash-current' } }
|
||||
]
|
||||
}
|
||||
}).then(function (response) {
|
||||
// ...
|
||||
}, errorHandler);
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
|
||||
@ -111,26 +111,21 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get the number of all documents in the cluster
|
||||
[source,js]
|
||||
---------
|
||||
client.count(function (error, response, status) {
|
||||
// check for and handle error
|
||||
var count = response.count;
|
||||
});
|
||||
const { count } = await client.count();
|
||||
---------
|
||||
|
||||
.Get the number of documents in an index
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Get the number of documents matching a query
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name',
|
||||
body: {
|
||||
query: {
|
||||
@ -143,8 +138,6 @@ client.count({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (err, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
@ -272,7 +265,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create a document
|
||||
[source,js]
|
||||
---------
|
||||
client.create({
|
||||
await client.create({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -283,12 +276,11 @@ client.create({
|
||||
published_at: '2013-01-01',
|
||||
counter: 1
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -353,16 +345,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Delete the document `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.delete({
|
||||
await client.delete({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -423,30 +414,27 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Deleting documents with a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'myindex',
|
||||
q: 'test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Deleting documents using the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'posts',
|
||||
body: {
|
||||
query: {
|
||||
term: { published: false }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -587,20 +575,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Check that the document `/myindex/mytype/1` exist
|
||||
[source,js]
|
||||
---------
|
||||
client.exists({
|
||||
const exists = await client.exists({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, exists) {
|
||||
if (exists === true) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -640,7 +623,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.See how a document is scored against a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
// the document to test
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
@ -648,15 +631,13 @@ client.explain({
|
||||
|
||||
// the query to score it against
|
||||
q: 'field:value'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.See how a document is scored against a query written in the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -665,12 +646,11 @@ client.explain({
|
||||
match: { title: 'test' }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -777,16 +757,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.get({
|
||||
const response = await client.get({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -969,7 +948,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create or update a document
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
const response = await client.index({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -978,12 +957,11 @@ client.index({
|
||||
tags: ['y', 'z'],
|
||||
published: true,
|
||||
}
|
||||
}, function (error, response) {
|
||||
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1070,7 +1048,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.An array of doc locations. Useful for getting documents from different indices.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
body: {
|
||||
docs: [
|
||||
{ _index: 'indexA', _type: 'typeA', _id: '1' },
|
||||
@ -1078,26 +1056,23 @@ client.mget({
|
||||
{ _index: 'indexC', _type: 'typeC', _id: '1' }
|
||||
]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.An array of ids. You must also specify the `index` and `type` that apply to all of the ids.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
ids: [1, 2, 3]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1139,17 +1114,16 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Search for similar documents using the `title` property of document `myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.mlt({
|
||||
const response = await client.mlt({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1,
|
||||
mlt_fields: 'title'
|
||||
}, function (errors, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1254,7 +1228,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform multiple different searches, the body is made up of meta/data pairs
|
||||
[source,js]
|
||||
---------
|
||||
client.msearch({
|
||||
const response = await client.msearch({
|
||||
body: [
|
||||
// match all query, on all indices and types
|
||||
{},
|
||||
@ -1355,43 +1329,41 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.First, Register queries named “alert-1” and “alert-2” for the “myindex” index
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
await Promise.all([
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
}),
|
||||
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
})
|
||||
]);
|
||||
---------
|
||||
|
||||
.Then you can send documents to learn which query `_percolator` queries they match
|
||||
[source,js]
|
||||
---------
|
||||
client.percolate({
|
||||
const response1 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1399,15 +1371,15 @@ client.percolate({
|
||||
title: "Foo"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
});
|
||||
|
||||
client.percolate({
|
||||
// response1 should look something like
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
|
||||
const response2 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1415,19 +1387,20 @@ client.percolate({
|
||||
title: "Foo Bar"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
// response2 should look something like
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1656,18 +1629,16 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Search with a simple query string query
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
q: 'title:test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Passing a full request definition in the Elasticsearch's Query DSL as a `Hash`
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
query: {
|
||||
@ -1683,12 +1654,11 @@ client.search({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1966,17 +1936,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Return query terms suggestions (“auto-correction”)
|
||||
[source,js]
|
||||
---------
|
||||
client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
const response = await client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
});
|
||||
|
||||
// response will be formatted like so:
|
||||
//
|
||||
// {
|
||||
@ -1995,10 +1966,11 @@ body: {
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -2092,7 +2064,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Update document title using partial document
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2102,15 +2074,13 @@ client.update({
|
||||
title: 'Updated'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Add a tag to document `tags` property using a `script`
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2118,15 +2088,13 @@ client.update({
|
||||
script: 'ctx._source.tags += tag',
|
||||
params: { tag: 'some new tag' }
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Increment a document counter by 1 or initialize it, when the document does not exist
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '777',
|
||||
@ -2136,15 +2104,13 @@ client.update({
|
||||
counter: 1
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Delete a document if it's tagged “to-delete”
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2154,12 +2120,11 @@ client.update({
|
||||
tag: 'to-delete'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -4340,19 +4305,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform an atomic alias swap, for a rotating index
|
||||
[source,js]
|
||||
---------
|
||||
client.indices.updateAliases({
|
||||
const response = await client.indices.updateAliases({
|
||||
body: {
|
||||
actions: [
|
||||
{ remove: { index: 'logstash-2014.04', alias: 'logstash-current' } },
|
||||
{ add: { index: 'logstash-2014.05', alias: 'logstash-current' } }
|
||||
]
|
||||
}
|
||||
}).then(function (response) {
|
||||
// ...
|
||||
}, errorHandler);
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
|
||||
@ -107,26 +107,21 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get the number of all documents in the cluster
|
||||
[source,js]
|
||||
---------
|
||||
client.count(function (error, response, status) {
|
||||
// check for and handle error
|
||||
var count = response.count;
|
||||
});
|
||||
const { count } = await client.count();
|
||||
---------
|
||||
|
||||
.Get the number of documents in an index
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Get the number of documents matching a query
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name',
|
||||
body: {
|
||||
query: {
|
||||
@ -139,8 +134,6 @@ client.count({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (err, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
@ -268,7 +261,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create a document
|
||||
[source,js]
|
||||
---------
|
||||
client.create({
|
||||
await client.create({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -279,12 +272,11 @@ client.create({
|
||||
published_at: '2013-01-01',
|
||||
counter: 1
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -343,16 +335,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Delete the document `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.delete({
|
||||
await client.delete({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -479,20 +470,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Check that the document `/myindex/mytype/1` exist
|
||||
[source,js]
|
||||
---------
|
||||
client.exists({
|
||||
const exists = await client.exists({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, exists) {
|
||||
if (exists === true) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -532,7 +518,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.See how a document is scored against a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
// the document to test
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
@ -540,15 +526,13 @@ client.explain({
|
||||
|
||||
// the query to score it against
|
||||
q: 'field:value'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.See how a document is scored against a query written in the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -557,12 +541,11 @@ client.explain({
|
||||
match: { title: 'test' }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -669,16 +652,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.get({
|
||||
const response = await client.get({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -861,7 +843,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create or update a document
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
const response = await client.index({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -870,12 +852,11 @@ client.index({
|
||||
tags: ['y', 'z'],
|
||||
published: true,
|
||||
}
|
||||
}, function (error, response) {
|
||||
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -956,7 +937,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.An array of doc locations. Useful for getting documents from different indices.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
body: {
|
||||
docs: [
|
||||
{ _index: 'indexA', _type: 'typeA', _id: '1' },
|
||||
@ -964,26 +945,23 @@ client.mget({
|
||||
{ _index: 'indexC', _type: 'typeC', _id: '1' }
|
||||
]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.An array of ids. You must also specify the `index` and `type` that apply to all of the ids.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
ids: [1, 2, 3]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1066,7 +1044,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform multiple different searches, the body is made up of meta/data pairs
|
||||
[source,js]
|
||||
---------
|
||||
client.msearch({
|
||||
const response = await client.msearch({
|
||||
body: [
|
||||
// match all query, on all indices and types
|
||||
{},
|
||||
@ -1177,43 +1155,41 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.First, Register queries named “alert-1” and “alert-2” for the “myindex” index
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
await Promise.all([
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
}),
|
||||
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
})
|
||||
]);
|
||||
---------
|
||||
|
||||
.Then you can send documents to learn which query `_percolator` queries they match
|
||||
[source,js]
|
||||
---------
|
||||
client.percolate({
|
||||
const response1 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1221,15 +1197,15 @@ client.percolate({
|
||||
title: "Foo"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
});
|
||||
|
||||
client.percolate({
|
||||
// response1 should look something like
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
|
||||
const response2 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1237,19 +1213,20 @@ client.percolate({
|
||||
title: "Foo Bar"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
// response2 should look something like
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1568,18 +1545,16 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Search with a simple query string query
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
q: 'title:test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Passing a full request definition in the Elasticsearch's Query DSL as a `Hash`
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
query: {
|
||||
@ -1595,12 +1570,11 @@ client.search({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1878,17 +1852,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Return query terms suggestions (“auto-correction”)
|
||||
[source,js]
|
||||
---------
|
||||
client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
const response = await client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
});
|
||||
|
||||
// response will be formatted like so:
|
||||
//
|
||||
// {
|
||||
@ -1907,10 +1882,11 @@ body: {
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -2016,7 +1992,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Update document title using partial document
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2026,15 +2002,13 @@ client.update({
|
||||
title: 'Updated'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Add a tag to document `tags` property using a `script`
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2042,15 +2016,13 @@ client.update({
|
||||
script: 'ctx._source.tags += tag',
|
||||
params: { tag: 'some new tag' }
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Increment a document counter by 1 or initialize it, when the document does not exist
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '777',
|
||||
@ -2060,15 +2032,13 @@ client.update({
|
||||
counter: 1
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Delete a document if it's tagged “to-delete”
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2078,12 +2048,11 @@ client.update({
|
||||
tag: 'to-delete'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -4514,19 +4483,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform an atomic alias swap, for a rotating index
|
||||
[source,js]
|
||||
---------
|
||||
client.indices.updateAliases({
|
||||
const response = await client.indices.updateAliases({
|
||||
body: {
|
||||
actions: [
|
||||
{ remove: { index: 'logstash-2014.04', alias: 'logstash-current' } },
|
||||
{ add: { index: 'logstash-2014.05', alias: 'logstash-current' } }
|
||||
]
|
||||
}
|
||||
}).then(function (response) {
|
||||
// ...
|
||||
}, errorHandler);
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
|
||||
@ -116,26 +116,21 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get the number of all documents in the cluster
|
||||
[source,js]
|
||||
---------
|
||||
client.count(function (error, response, status) {
|
||||
// check for and handle error
|
||||
var count = response.count;
|
||||
});
|
||||
const { count } = await client.count();
|
||||
---------
|
||||
|
||||
.Get the number of documents in an index
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Get the number of documents matching a query
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name',
|
||||
body: {
|
||||
query: {
|
||||
@ -148,8 +143,6 @@ client.count({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (err, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
@ -277,7 +270,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create a document
|
||||
[source,js]
|
||||
---------
|
||||
client.create({
|
||||
await client.create({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -288,12 +281,11 @@ client.create({
|
||||
published_at: '2013-01-01',
|
||||
counter: 1
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -355,16 +347,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Delete the document `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.delete({
|
||||
await client.delete({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -420,30 +411,27 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Deleting documents with a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'myindex',
|
||||
q: 'test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Deleting documents using the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'posts',
|
||||
body: {
|
||||
query: {
|
||||
term: { published: false }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -605,20 +593,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Check that the document `/myindex/mytype/1` exist
|
||||
[source,js]
|
||||
---------
|
||||
client.exists({
|
||||
const exists = await client.exists({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, exists) {
|
||||
if (exists === true) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -658,7 +641,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.See how a document is scored against a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
// the document to test
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
@ -666,15 +649,13 @@ client.explain({
|
||||
|
||||
// the query to score it against
|
||||
q: 'field:value'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.See how a document is scored against a query written in the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -683,12 +664,11 @@ client.explain({
|
||||
match: { title: 'test' }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -795,16 +775,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.get({
|
||||
const response = await client.get({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -967,7 +946,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create or update a document
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
const response = await client.index({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -976,12 +955,11 @@ client.index({
|
||||
tags: ['y', 'z'],
|
||||
published: true,
|
||||
}
|
||||
}, function (error, response) {
|
||||
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1065,7 +1043,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.An array of doc locations. Useful for getting documents from different indices.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
body: {
|
||||
docs: [
|
||||
{ _index: 'indexA', _type: 'typeA', _id: '1' },
|
||||
@ -1073,26 +1051,23 @@ client.mget({
|
||||
{ _index: 'indexC', _type: 'typeC', _id: '1' }
|
||||
]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.An array of ids. You must also specify the `index` and `type` that apply to all of the ids.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
ids: [1, 2, 3]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1175,7 +1150,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform multiple different searches, the body is made up of meta/data pairs
|
||||
[source,js]
|
||||
---------
|
||||
client.msearch({
|
||||
const response = await client.msearch({
|
||||
body: [
|
||||
// match all query, on all indices and types
|
||||
{},
|
||||
@ -1321,43 +1296,41 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.First, Register queries named “alert-1” and “alert-2” for the “myindex” index
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
await Promise.all([
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
}),
|
||||
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
})
|
||||
]);
|
||||
---------
|
||||
|
||||
.Then you can send documents to learn which query `_percolator` queries they match
|
||||
[source,js]
|
||||
---------
|
||||
client.percolate({
|
||||
const response1 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1365,15 +1338,15 @@ client.percolate({
|
||||
title: "Foo"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
});
|
||||
|
||||
client.percolate({
|
||||
// response1 should look something like
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
|
||||
const response2 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1381,19 +1354,20 @@ client.percolate({
|
||||
title: "Foo Bar"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
// response2 should look something like
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1615,30 +1589,40 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Collect every title in the index that contains the word "test"
|
||||
[source,js]
|
||||
---------
|
||||
var allTitles = [];
|
||||
const allTitles = [];
|
||||
const responseQueue = [];
|
||||
|
||||
// first we do a search, and specify a scroll timeout
|
||||
client.search({
|
||||
// start things off by searching, setting a scroll timeout, and pushing
|
||||
// our first response into the queue to be processed
|
||||
await client.search({
|
||||
index: 'myindex',
|
||||
scroll: '30s', // keep the search results "scrollable" for 30 seconds
|
||||
source: ['title'], // filter the source to only include the title field
|
||||
q: 'title:test'
|
||||
}, function getMoreUntilDone(error, response) {
|
||||
// collect the title from each response
|
||||
})
|
||||
|
||||
while (responseQueue.length) {
|
||||
const response = responseQueue.shift();
|
||||
|
||||
// collect the titles from this response
|
||||
response.hits.hits.forEach(function (hit) {
|
||||
allTitles.push(hit._source.title);
|
||||
allTitles.push(hit.fields.title);
|
||||
});
|
||||
|
||||
if (response.hits.total > allTitles.length) {
|
||||
// ask elasticsearch for the next set of hits from this search
|
||||
client.scroll({
|
||||
// check to see if we have collected all of the titles
|
||||
if (response.hits.total === allTitles.length) {
|
||||
console.log('every "test" title', allTitles);
|
||||
break
|
||||
}
|
||||
|
||||
// get the next response if there are more titles to fetch
|
||||
responseQueue.push(
|
||||
await client.scroll({
|
||||
scrollId: response._scroll_id,
|
||||
scroll: '30s'
|
||||
}, getMoreUntilDone);
|
||||
} else {
|
||||
console.log('every "test" title', allTitles);
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
---------
|
||||
|
||||
|
||||
@ -1674,18 +1658,16 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Search with a simple query string query
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
q: 'title:test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Passing a full request definition in the Elasticsearch's Query DSL as a `Hash`
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
query: {
|
||||
@ -1701,12 +1683,11 @@ client.search({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1919,17 +1900,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Return query terms suggestions (“auto-correction”)
|
||||
[source,js]
|
||||
---------
|
||||
client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
const response = await client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
});
|
||||
|
||||
// response will be formatted like so:
|
||||
//
|
||||
// {
|
||||
@ -1948,10 +1930,11 @@ body: {
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -2055,7 +2038,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Update document title using partial document
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2065,15 +2048,13 @@ client.update({
|
||||
title: 'Updated'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Add a tag to document `tags` property using a `script`
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2081,15 +2062,13 @@ client.update({
|
||||
script: 'ctx._source.tags += tag',
|
||||
params: { tag: 'some new tag' }
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Increment a document counter by 1 or initialize it, when the document does not exist
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '777',
|
||||
@ -2099,15 +2078,13 @@ client.update({
|
||||
counter: 1
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Delete a document if it's tagged “to-delete”
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2117,12 +2094,11 @@ client.update({
|
||||
tag: 'to-delete'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -4561,19 +4537,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform an atomic alias swap, for a rotating index
|
||||
[source,js]
|
||||
---------
|
||||
client.indices.updateAliases({
|
||||
const response = await client.indices.updateAliases({
|
||||
body: {
|
||||
actions: [
|
||||
{ remove: { index: 'logstash-2014.04', alias: 'logstash-current' } },
|
||||
{ add: { index: 'logstash-2014.05', alias: 'logstash-current' } }
|
||||
]
|
||||
}
|
||||
}).then(function (response) {
|
||||
// ...
|
||||
}, errorHandler);
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
|
||||
@ -116,26 +116,21 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get the number of all documents in the cluster
|
||||
[source,js]
|
||||
---------
|
||||
client.count(function (error, response, status) {
|
||||
// check for and handle error
|
||||
var count = response.count;
|
||||
});
|
||||
const { count } = await client.count();
|
||||
---------
|
||||
|
||||
.Get the number of documents in an index
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Get the number of documents matching a query
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name',
|
||||
body: {
|
||||
query: {
|
||||
@ -148,8 +143,6 @@ client.count({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (err, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
@ -275,7 +268,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create a document
|
||||
[source,js]
|
||||
---------
|
||||
client.create({
|
||||
await client.create({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -286,12 +279,11 @@ client.create({
|
||||
published_at: '2013-01-01',
|
||||
counter: 1
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -353,16 +345,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Delete the document `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.delete({
|
||||
await client.delete({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -418,30 +409,27 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Deleting documents with a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'myindex',
|
||||
q: 'test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Deleting documents using the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'posts',
|
||||
body: {
|
||||
query: {
|
||||
term: { published: false }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -603,20 +591,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Check that the document `/myindex/mytype/1` exist
|
||||
[source,js]
|
||||
---------
|
||||
client.exists({
|
||||
const exists = await client.exists({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, exists) {
|
||||
if (exists === true) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -656,7 +639,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.See how a document is scored against a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
// the document to test
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
@ -664,15 +647,13 @@ client.explain({
|
||||
|
||||
// the query to score it against
|
||||
q: 'field:value'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.See how a document is scored against a query written in the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -681,12 +662,11 @@ client.explain({
|
||||
match: { title: 'test' }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -791,16 +771,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.get({
|
||||
const response = await client.get({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -963,7 +942,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create or update a document
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
const response = await client.index({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -972,12 +951,11 @@ client.index({
|
||||
tags: ['y', 'z'],
|
||||
published: true,
|
||||
}
|
||||
}, function (error, response) {
|
||||
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1061,7 +1039,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.An array of doc locations. Useful for getting documents from different indices.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
body: {
|
||||
docs: [
|
||||
{ _index: 'indexA', _type: 'typeA', _id: '1' },
|
||||
@ -1069,26 +1047,23 @@ client.mget({
|
||||
{ _index: 'indexC', _type: 'typeC', _id: '1' }
|
||||
]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.An array of ids. You must also specify the `index` and `type` that apply to all of the ids.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
ids: [1, 2, 3]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1171,7 +1146,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform multiple different searches, the body is made up of meta/data pairs
|
||||
[source,js]
|
||||
---------
|
||||
client.msearch({
|
||||
const response = await client.msearch({
|
||||
body: [
|
||||
// match all query, on all indices and types
|
||||
{},
|
||||
@ -1317,43 +1292,41 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.First, Register queries named “alert-1” and “alert-2” for the “myindex” index
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
await Promise.all([
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
}),
|
||||
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
})
|
||||
]);
|
||||
---------
|
||||
|
||||
.Then you can send documents to learn which query `_percolator` queries they match
|
||||
[source,js]
|
||||
---------
|
||||
client.percolate({
|
||||
const response1 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1361,15 +1334,15 @@ client.percolate({
|
||||
title: "Foo"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
});
|
||||
|
||||
client.percolate({
|
||||
// response1 should look something like
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
|
||||
const response2 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1377,19 +1350,20 @@ client.percolate({
|
||||
title: "Foo Bar"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
// response2 should look something like
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1613,30 +1587,40 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Collect every title in the index that contains the word "test"
|
||||
[source,js]
|
||||
---------
|
||||
var allTitles = [];
|
||||
const allTitles = [];
|
||||
const responseQueue = [];
|
||||
|
||||
// first we do a search, and specify a scroll timeout
|
||||
client.search({
|
||||
// start things off by searching, setting a scroll timeout, and pushing
|
||||
// our first response into the queue to be processed
|
||||
await client.search({
|
||||
index: 'myindex',
|
||||
scroll: '30s', // keep the search results "scrollable" for 30 seconds
|
||||
source: ['title'], // filter the source to only include the title field
|
||||
q: 'title:test'
|
||||
}, function getMoreUntilDone(error, response) {
|
||||
// collect the title from each response
|
||||
})
|
||||
|
||||
while (responseQueue.length) {
|
||||
const response = responseQueue.shift();
|
||||
|
||||
// collect the titles from this response
|
||||
response.hits.hits.forEach(function (hit) {
|
||||
allTitles.push(hit._source.title);
|
||||
allTitles.push(hit.fields.title);
|
||||
});
|
||||
|
||||
if (response.hits.total > allTitles.length) {
|
||||
// ask elasticsearch for the next set of hits from this search
|
||||
client.scroll({
|
||||
// check to see if we have collected all of the titles
|
||||
if (response.hits.total === allTitles.length) {
|
||||
console.log('every "test" title', allTitles);
|
||||
break
|
||||
}
|
||||
|
||||
// get the next response if there are more titles to fetch
|
||||
responseQueue.push(
|
||||
await client.scroll({
|
||||
scrollId: response._scroll_id,
|
||||
scroll: '30s'
|
||||
}, getMoreUntilDone);
|
||||
} else {
|
||||
console.log('every "test" title', allTitles);
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
---------
|
||||
|
||||
|
||||
@ -1672,18 +1656,16 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Search with a simple query string query
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
q: 'title:test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Passing a full request definition in the Elasticsearch's Query DSL as a `Hash`
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
query: {
|
||||
@ -1699,12 +1681,11 @@ client.search({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1919,17 +1900,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Return query terms suggestions (“auto-correction”)
|
||||
[source,js]
|
||||
---------
|
||||
client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
const response = await client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
});
|
||||
|
||||
// response will be formatted like so:
|
||||
//
|
||||
// {
|
||||
@ -1948,10 +1930,11 @@ body: {
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -2055,7 +2038,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Update document title using partial document
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2065,15 +2048,13 @@ client.update({
|
||||
title: 'Updated'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Add a tag to document `tags` property using a `script`
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2081,15 +2062,13 @@ client.update({
|
||||
script: 'ctx._source.tags += tag',
|
||||
params: { tag: 'some new tag' }
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Increment a document counter by 1 or initialize it, when the document does not exist
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '777',
|
||||
@ -2099,15 +2078,13 @@ client.update({
|
||||
counter: 1
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Delete a document if it's tagged “to-delete”
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2117,12 +2094,11 @@ client.update({
|
||||
tag: 'to-delete'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -4638,19 +4614,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform an atomic alias swap, for a rotating index
|
||||
[source,js]
|
||||
---------
|
||||
client.indices.updateAliases({
|
||||
const response = await client.indices.updateAliases({
|
||||
body: {
|
||||
actions: [
|
||||
{ remove: { index: 'logstash-2014.04', alias: 'logstash-current' } },
|
||||
{ add: { index: 'logstash-2014.05', alias: 'logstash-current' } }
|
||||
]
|
||||
}
|
||||
}).then(function (response) {
|
||||
// ...
|
||||
}, errorHandler);
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
|
||||
@ -116,26 +116,21 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get the number of all documents in the cluster
|
||||
[source,js]
|
||||
---------
|
||||
client.count(function (error, response, status) {
|
||||
// check for and handle error
|
||||
var count = response.count;
|
||||
});
|
||||
const { count } = await client.count();
|
||||
---------
|
||||
|
||||
.Get the number of documents in an index
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Get the number of documents matching a query
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name',
|
||||
body: {
|
||||
query: {
|
||||
@ -148,8 +143,6 @@ client.count({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (err, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
@ -275,7 +268,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create a document
|
||||
[source,js]
|
||||
---------
|
||||
client.create({
|
||||
await client.create({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -286,12 +279,11 @@ client.create({
|
||||
published_at: '2013-01-01',
|
||||
counter: 1
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -353,16 +345,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Delete the document `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.delete({
|
||||
await client.delete({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -418,30 +409,27 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Deleting documents with a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'myindex',
|
||||
q: 'test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Deleting documents using the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'posts',
|
||||
body: {
|
||||
query: {
|
||||
term: { published: false }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -603,20 +591,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Check that the document `/myindex/mytype/1` exist
|
||||
[source,js]
|
||||
---------
|
||||
client.exists({
|
||||
const exists = await client.exists({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, exists) {
|
||||
if (exists === true) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -656,7 +639,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.See how a document is scored against a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
// the document to test
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
@ -664,15 +647,13 @@ client.explain({
|
||||
|
||||
// the query to score it against
|
||||
q: 'field:value'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.See how a document is scored against a query written in the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -681,12 +662,11 @@ client.explain({
|
||||
match: { title: 'test' }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -791,16 +771,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.get({
|
||||
const response = await client.get({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -963,7 +942,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create or update a document
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
const response = await client.index({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -972,12 +951,11 @@ client.index({
|
||||
tags: ['y', 'z'],
|
||||
published: true,
|
||||
}
|
||||
}, function (error, response) {
|
||||
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1061,7 +1039,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.An array of doc locations. Useful for getting documents from different indices.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
body: {
|
||||
docs: [
|
||||
{ _index: 'indexA', _type: 'typeA', _id: '1' },
|
||||
@ -1069,26 +1047,23 @@ client.mget({
|
||||
{ _index: 'indexC', _type: 'typeC', _id: '1' }
|
||||
]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.An array of ids. You must also specify the `index` and `type` that apply to all of the ids.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
ids: [1, 2, 3]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1171,7 +1146,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform multiple different searches, the body is made up of meta/data pairs
|
||||
[source,js]
|
||||
---------
|
||||
client.msearch({
|
||||
const response = await client.msearch({
|
||||
body: [
|
||||
// match all query, on all indices and types
|
||||
{},
|
||||
@ -1317,43 +1292,41 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.First, Register queries named “alert-1” and “alert-2” for the “myindex” index
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
await Promise.all([
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
}),
|
||||
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
})
|
||||
]);
|
||||
---------
|
||||
|
||||
.Then you can send documents to learn which query `_percolator` queries they match
|
||||
[source,js]
|
||||
---------
|
||||
client.percolate({
|
||||
const response1 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1361,15 +1334,15 @@ client.percolate({
|
||||
title: "Foo"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
});
|
||||
|
||||
client.percolate({
|
||||
// response1 should look something like
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
|
||||
const response2 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1377,19 +1350,20 @@ client.percolate({
|
||||
title: "Foo Bar"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
// response2 should look something like
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1613,30 +1587,40 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Collect every title in the index that contains the word "test"
|
||||
[source,js]
|
||||
---------
|
||||
var allTitles = [];
|
||||
const allTitles = [];
|
||||
const responseQueue = [];
|
||||
|
||||
// first we do a search, and specify a scroll timeout
|
||||
client.search({
|
||||
// start things off by searching, setting a scroll timeout, and pushing
|
||||
// our first response into the queue to be processed
|
||||
await client.search({
|
||||
index: 'myindex',
|
||||
scroll: '30s', // keep the search results "scrollable" for 30 seconds
|
||||
source: ['title'], // filter the source to only include the title field
|
||||
q: 'title:test'
|
||||
}, function getMoreUntilDone(error, response) {
|
||||
// collect the title from each response
|
||||
})
|
||||
|
||||
while (responseQueue.length) {
|
||||
const response = responseQueue.shift();
|
||||
|
||||
// collect the titles from this response
|
||||
response.hits.hits.forEach(function (hit) {
|
||||
allTitles.push(hit._source.title);
|
||||
allTitles.push(hit.fields.title);
|
||||
});
|
||||
|
||||
if (response.hits.total > allTitles.length) {
|
||||
// ask elasticsearch for the next set of hits from this search
|
||||
client.scroll({
|
||||
// check to see if we have collected all of the titles
|
||||
if (response.hits.total === allTitles.length) {
|
||||
console.log('every "test" title', allTitles);
|
||||
break
|
||||
}
|
||||
|
||||
// get the next response if there are more titles to fetch
|
||||
responseQueue.push(
|
||||
await client.scroll({
|
||||
scrollId: response._scroll_id,
|
||||
scroll: '30s'
|
||||
}, getMoreUntilDone);
|
||||
} else {
|
||||
console.log('every "test" title', allTitles);
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
---------
|
||||
|
||||
|
||||
@ -1672,18 +1656,16 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Search with a simple query string query
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
q: 'title:test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Passing a full request definition in the Elasticsearch's Query DSL as a `Hash`
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
query: {
|
||||
@ -1699,12 +1681,11 @@ client.search({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1919,17 +1900,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Return query terms suggestions (“auto-correction”)
|
||||
[source,js]
|
||||
---------
|
||||
client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
const response = await client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
});
|
||||
|
||||
// response will be formatted like so:
|
||||
//
|
||||
// {
|
||||
@ -1948,10 +1930,11 @@ body: {
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -2055,7 +2038,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Update document title using partial document
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2065,15 +2048,13 @@ client.update({
|
||||
title: 'Updated'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Add a tag to document `tags` property using a `script`
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2081,15 +2062,13 @@ client.update({
|
||||
script: 'ctx._source.tags += tag',
|
||||
params: { tag: 'some new tag' }
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Increment a document counter by 1 or initialize it, when the document does not exist
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '777',
|
||||
@ -2099,15 +2078,13 @@ client.update({
|
||||
counter: 1
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Delete a document if it's tagged “to-delete”
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2117,12 +2094,11 @@ client.update({
|
||||
tag: 'to-delete'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -4638,19 +4614,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform an atomic alias swap, for a rotating index
|
||||
[source,js]
|
||||
---------
|
||||
client.indices.updateAliases({
|
||||
const response = await client.indices.updateAliases({
|
||||
body: {
|
||||
actions: [
|
||||
{ remove: { index: 'logstash-2014.04', alias: 'logstash-current' } },
|
||||
{ add: { index: 'logstash-2014.05', alias: 'logstash-current' } }
|
||||
]
|
||||
}
|
||||
}).then(function (response) {
|
||||
// ...
|
||||
}, errorHandler);
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
|
||||
@ -116,26 +116,21 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get the number of all documents in the cluster
|
||||
[source,js]
|
||||
---------
|
||||
client.count(function (error, response, status) {
|
||||
// check for and handle error
|
||||
var count = response.count;
|
||||
});
|
||||
const { count } = await client.count();
|
||||
---------
|
||||
|
||||
.Get the number of documents in an index
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Get the number of documents matching a query
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name',
|
||||
body: {
|
||||
query: {
|
||||
@ -148,8 +143,6 @@ client.count({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (err, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
@ -275,7 +268,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create a document
|
||||
[source,js]
|
||||
---------
|
||||
client.create({
|
||||
await client.create({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -286,12 +279,11 @@ client.create({
|
||||
published_at: '2013-01-01',
|
||||
counter: 1
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -353,16 +345,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Delete the document `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.delete({
|
||||
await client.delete({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -418,30 +409,27 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Deleting documents with a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'myindex',
|
||||
q: 'test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Deleting documents using the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'posts',
|
||||
body: {
|
||||
query: {
|
||||
term: { published: false }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -603,20 +591,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Check that the document `/myindex/mytype/1` exist
|
||||
[source,js]
|
||||
---------
|
||||
client.exists({
|
||||
const exists = await client.exists({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, exists) {
|
||||
if (exists === true) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -656,7 +639,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.See how a document is scored against a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
// the document to test
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
@ -664,15 +647,13 @@ client.explain({
|
||||
|
||||
// the query to score it against
|
||||
q: 'field:value'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.See how a document is scored against a query written in the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -681,12 +662,11 @@ client.explain({
|
||||
match: { title: 'test' }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -791,16 +771,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.get({
|
||||
const response = await client.get({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -963,7 +942,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create or update a document
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
const response = await client.index({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -972,12 +951,11 @@ client.index({
|
||||
tags: ['y', 'z'],
|
||||
published: true,
|
||||
}
|
||||
}, function (error, response) {
|
||||
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1061,7 +1039,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.An array of doc locations. Useful for getting documents from different indices.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
body: {
|
||||
docs: [
|
||||
{ _index: 'indexA', _type: 'typeA', _id: '1' },
|
||||
@ -1069,26 +1047,23 @@ client.mget({
|
||||
{ _index: 'indexC', _type: 'typeC', _id: '1' }
|
||||
]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.An array of ids. You must also specify the `index` and `type` that apply to all of the ids.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
ids: [1, 2, 3]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1171,7 +1146,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform multiple different searches, the body is made up of meta/data pairs
|
||||
[source,js]
|
||||
---------
|
||||
client.msearch({
|
||||
const response = await client.msearch({
|
||||
body: [
|
||||
// match all query, on all indices and types
|
||||
{},
|
||||
@ -1317,43 +1292,41 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.First, Register queries named “alert-1” and “alert-2” for the “myindex” index
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
await Promise.all([
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
}),
|
||||
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
})
|
||||
]);
|
||||
---------
|
||||
|
||||
.Then you can send documents to learn which query `_percolator` queries they match
|
||||
[source,js]
|
||||
---------
|
||||
client.percolate({
|
||||
const response1 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1361,15 +1334,15 @@ client.percolate({
|
||||
title: "Foo"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
});
|
||||
|
||||
client.percolate({
|
||||
// response1 should look something like
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
|
||||
const response2 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1377,19 +1350,20 @@ client.percolate({
|
||||
title: "Foo Bar"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
// response2 should look something like
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1613,30 +1587,40 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Collect every title in the index that contains the word "test"
|
||||
[source,js]
|
||||
---------
|
||||
var allTitles = [];
|
||||
const allTitles = [];
|
||||
const responseQueue = [];
|
||||
|
||||
// first we do a search, and specify a scroll timeout
|
||||
client.search({
|
||||
// start things off by searching, setting a scroll timeout, and pushing
|
||||
// our first response into the queue to be processed
|
||||
await client.search({
|
||||
index: 'myindex',
|
||||
scroll: '30s', // keep the search results "scrollable" for 30 seconds
|
||||
source: ['title'], // filter the source to only include the title field
|
||||
q: 'title:test'
|
||||
}, function getMoreUntilDone(error, response) {
|
||||
// collect the title from each response
|
||||
})
|
||||
|
||||
while (responseQueue.length) {
|
||||
const response = responseQueue.shift();
|
||||
|
||||
// collect the titles from this response
|
||||
response.hits.hits.forEach(function (hit) {
|
||||
allTitles.push(hit._source.title);
|
||||
allTitles.push(hit.fields.title);
|
||||
});
|
||||
|
||||
if (response.hits.total > allTitles.length) {
|
||||
// ask elasticsearch for the next set of hits from this search
|
||||
client.scroll({
|
||||
// check to see if we have collected all of the titles
|
||||
if (response.hits.total === allTitles.length) {
|
||||
console.log('every "test" title', allTitles);
|
||||
break
|
||||
}
|
||||
|
||||
// get the next response if there are more titles to fetch
|
||||
responseQueue.push(
|
||||
await client.scroll({
|
||||
scrollId: response._scroll_id,
|
||||
scroll: '30s'
|
||||
}, getMoreUntilDone);
|
||||
} else {
|
||||
console.log('every "test" title', allTitles);
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
---------
|
||||
|
||||
|
||||
@ -1672,18 +1656,16 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Search with a simple query string query
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
q: 'title:test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Passing a full request definition in the Elasticsearch's Query DSL as a `Hash`
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
query: {
|
||||
@ -1699,12 +1681,11 @@ client.search({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1919,17 +1900,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Return query terms suggestions (“auto-correction”)
|
||||
[source,js]
|
||||
---------
|
||||
client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
const response = await client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
});
|
||||
|
||||
// response will be formatted like so:
|
||||
//
|
||||
// {
|
||||
@ -1948,10 +1930,11 @@ body: {
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -2055,7 +2038,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Update document title using partial document
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2065,15 +2048,13 @@ client.update({
|
||||
title: 'Updated'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Add a tag to document `tags` property using a `script`
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2081,15 +2062,13 @@ client.update({
|
||||
script: 'ctx._source.tags += tag',
|
||||
params: { tag: 'some new tag' }
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Increment a document counter by 1 or initialize it, when the document does not exist
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '777',
|
||||
@ -2099,15 +2078,13 @@ client.update({
|
||||
counter: 1
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Delete a document if it's tagged “to-delete”
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2117,12 +2094,11 @@ client.update({
|
||||
tag: 'to-delete'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -4624,19 +4600,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform an atomic alias swap, for a rotating index
|
||||
[source,js]
|
||||
---------
|
||||
client.indices.updateAliases({
|
||||
const response = await client.indices.updateAliases({
|
||||
body: {
|
||||
actions: [
|
||||
{ remove: { index: 'logstash-2014.04', alias: 'logstash-current' } },
|
||||
{ add: { index: 'logstash-2014.05', alias: 'logstash-current' } }
|
||||
]
|
||||
}
|
||||
}).then(function (response) {
|
||||
// ...
|
||||
}, errorHandler);
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
|
||||
@ -116,26 +116,21 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get the number of all documents in the cluster
|
||||
[source,js]
|
||||
---------
|
||||
client.count(function (error, response, status) {
|
||||
// check for and handle error
|
||||
var count = response.count;
|
||||
});
|
||||
const { count } = await client.count();
|
||||
---------
|
||||
|
||||
.Get the number of documents in an index
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Get the number of documents matching a query
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name',
|
||||
body: {
|
||||
query: {
|
||||
@ -148,8 +143,6 @@ client.count({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (err, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
@ -275,7 +268,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create a document
|
||||
[source,js]
|
||||
---------
|
||||
client.create({
|
||||
await client.create({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -286,12 +279,11 @@ client.create({
|
||||
published_at: '2013-01-01',
|
||||
counter: 1
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -353,16 +345,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Delete the document `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.delete({
|
||||
await client.delete({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -418,30 +409,27 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Deleting documents with a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'myindex',
|
||||
q: 'test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Deleting documents using the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'posts',
|
||||
body: {
|
||||
query: {
|
||||
term: { published: false }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -603,20 +591,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Check that the document `/myindex/mytype/1` exist
|
||||
[source,js]
|
||||
---------
|
||||
client.exists({
|
||||
const exists = await client.exists({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, exists) {
|
||||
if (exists === true) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -729,7 +712,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.See how a document is scored against a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
// the document to test
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
@ -737,15 +720,13 @@ client.explain({
|
||||
|
||||
// the query to score it against
|
||||
q: 'field:value'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.See how a document is scored against a query written in the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -754,12 +735,11 @@ client.explain({
|
||||
match: { title: 'test' }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -903,16 +883,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.get({
|
||||
const response = await client.get({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1075,7 +1054,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create or update a document
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
const response = await client.index({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -1084,12 +1063,11 @@ client.index({
|
||||
tags: ['y', 'z'],
|
||||
published: true,
|
||||
}
|
||||
}, function (error, response) {
|
||||
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1173,7 +1151,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.An array of doc locations. Useful for getting documents from different indices.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
body: {
|
||||
docs: [
|
||||
{ _index: 'indexA', _type: 'typeA', _id: '1' },
|
||||
@ -1181,26 +1159,23 @@ client.mget({
|
||||
{ _index: 'indexC', _type: 'typeC', _id: '1' }
|
||||
]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.An array of ids. You must also specify the `index` and `type` that apply to all of the ids.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
ids: [1, 2, 3]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1283,7 +1258,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform multiple different searches, the body is made up of meta/data pairs
|
||||
[source,js]
|
||||
---------
|
||||
client.msearch({
|
||||
const response = await client.msearch({
|
||||
body: [
|
||||
// match all query, on all indices and types
|
||||
{},
|
||||
@ -1433,43 +1408,41 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.First, Register queries named “alert-1” and “alert-2” for the “myindex” index
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
await Promise.all([
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
}),
|
||||
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
})
|
||||
]);
|
||||
---------
|
||||
|
||||
.Then you can send documents to learn which query `_percolator` queries they match
|
||||
[source,js]
|
||||
---------
|
||||
client.percolate({
|
||||
const response1 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1477,15 +1450,15 @@ client.percolate({
|
||||
title: "Foo"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
});
|
||||
|
||||
client.percolate({
|
||||
// response1 should look something like
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
|
||||
const response2 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1493,19 +1466,20 @@ client.percolate({
|
||||
title: "Foo Bar"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
// response2 should look something like
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1729,30 +1703,40 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Collect every title in the index that contains the word "test"
|
||||
[source,js]
|
||||
---------
|
||||
var allTitles = [];
|
||||
const allTitles = [];
|
||||
const responseQueue = [];
|
||||
|
||||
// first we do a search, and specify a scroll timeout
|
||||
client.search({
|
||||
// start things off by searching, setting a scroll timeout, and pushing
|
||||
// our first response into the queue to be processed
|
||||
await client.search({
|
||||
index: 'myindex',
|
||||
scroll: '30s', // keep the search results "scrollable" for 30 seconds
|
||||
source: ['title'], // filter the source to only include the title field
|
||||
q: 'title:test'
|
||||
}, function getMoreUntilDone(error, response) {
|
||||
// collect the title from each response
|
||||
})
|
||||
|
||||
while (responseQueue.length) {
|
||||
const response = responseQueue.shift();
|
||||
|
||||
// collect the titles from this response
|
||||
response.hits.hits.forEach(function (hit) {
|
||||
allTitles.push(hit._source.title);
|
||||
allTitles.push(hit.fields.title);
|
||||
});
|
||||
|
||||
if (response.hits.total > allTitles.length) {
|
||||
// ask elasticsearch for the next set of hits from this search
|
||||
client.scroll({
|
||||
// check to see if we have collected all of the titles
|
||||
if (response.hits.total === allTitles.length) {
|
||||
console.log('every "test" title', allTitles);
|
||||
break
|
||||
}
|
||||
|
||||
// get the next response if there are more titles to fetch
|
||||
responseQueue.push(
|
||||
await client.scroll({
|
||||
scrollId: response._scroll_id,
|
||||
scroll: '30s'
|
||||
}, getMoreUntilDone);
|
||||
} else {
|
||||
console.log('every "test" title', allTitles);
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
---------
|
||||
|
||||
|
||||
@ -1788,18 +1772,16 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Search with a simple query string query
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
q: 'title:test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Passing a full request definition in the Elasticsearch's Query DSL as a `Hash`
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
query: {
|
||||
@ -1815,12 +1797,11 @@ client.search({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -2041,17 +2022,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Return query terms suggestions (“auto-correction”)
|
||||
[source,js]
|
||||
---------
|
||||
client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
const response = await client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
});
|
||||
|
||||
// response will be formatted like so:
|
||||
//
|
||||
// {
|
||||
@ -2070,10 +2052,11 @@ body: {
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -2177,7 +2160,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Update document title using partial document
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2187,15 +2170,13 @@ client.update({
|
||||
title: 'Updated'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Add a tag to document `tags` property using a `script`
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2203,15 +2184,13 @@ client.update({
|
||||
script: 'ctx._source.tags += tag',
|
||||
params: { tag: 'some new tag' }
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Increment a document counter by 1 or initialize it, when the document does not exist
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '777',
|
||||
@ -2221,15 +2200,13 @@ client.update({
|
||||
counter: 1
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Delete a document if it's tagged “to-delete”
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2239,12 +2216,11 @@ client.update({
|
||||
tag: 'to-delete'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -4754,19 +4730,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform an atomic alias swap, for a rotating index
|
||||
[source,js]
|
||||
---------
|
||||
client.indices.updateAliases({
|
||||
const response = await client.indices.updateAliases({
|
||||
body: {
|
||||
actions: [
|
||||
{ remove: { index: 'logstash-2014.04', alias: 'logstash-current' } },
|
||||
{ add: { index: 'logstash-2014.05', alias: 'logstash-current' } }
|
||||
]
|
||||
}
|
||||
}).then(function (response) {
|
||||
// ...
|
||||
}, errorHandler);
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
|
||||
@ -116,26 +116,21 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get the number of all documents in the cluster
|
||||
[source,js]
|
||||
---------
|
||||
client.count(function (error, response, status) {
|
||||
// check for and handle error
|
||||
var count = response.count;
|
||||
});
|
||||
const { count } = await client.count();
|
||||
---------
|
||||
|
||||
.Get the number of documents in an index
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Get the number of documents matching a query
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name',
|
||||
body: {
|
||||
query: {
|
||||
@ -148,8 +143,6 @@ client.count({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (err, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
@ -275,7 +268,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create a document
|
||||
[source,js]
|
||||
---------
|
||||
client.create({
|
||||
await client.create({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -286,12 +279,11 @@ client.create({
|
||||
published_at: '2013-01-01',
|
||||
counter: 1
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -353,16 +345,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Delete the document `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.delete({
|
||||
await client.delete({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -418,30 +409,27 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Deleting documents with a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'myindex',
|
||||
q: 'test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Deleting documents using the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'posts',
|
||||
body: {
|
||||
query: {
|
||||
term: { published: false }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -603,20 +591,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Check that the document `/myindex/mytype/1` exist
|
||||
[source,js]
|
||||
---------
|
||||
client.exists({
|
||||
const exists = await client.exists({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, exists) {
|
||||
if (exists === true) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -729,7 +712,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.See how a document is scored against a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
// the document to test
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
@ -737,15 +720,13 @@ client.explain({
|
||||
|
||||
// the query to score it against
|
||||
q: 'field:value'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.See how a document is scored against a query written in the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -754,12 +735,11 @@ client.explain({
|
||||
match: { title: 'test' }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -903,16 +883,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.get({
|
||||
const response = await client.get({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1075,7 +1054,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create or update a document
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
const response = await client.index({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -1084,12 +1063,11 @@ client.index({
|
||||
tags: ['y', 'z'],
|
||||
published: true,
|
||||
}
|
||||
}, function (error, response) {
|
||||
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1173,7 +1151,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.An array of doc locations. Useful for getting documents from different indices.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
body: {
|
||||
docs: [
|
||||
{ _index: 'indexA', _type: 'typeA', _id: '1' },
|
||||
@ -1181,26 +1159,23 @@ client.mget({
|
||||
{ _index: 'indexC', _type: 'typeC', _id: '1' }
|
||||
]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.An array of ids. You must also specify the `index` and `type` that apply to all of the ids.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
ids: [1, 2, 3]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1283,7 +1258,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform multiple different searches, the body is made up of meta/data pairs
|
||||
[source,js]
|
||||
---------
|
||||
client.msearch({
|
||||
const response = await client.msearch({
|
||||
body: [
|
||||
// match all query, on all indices and types
|
||||
{},
|
||||
@ -1435,43 +1410,41 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.First, Register queries named “alert-1” and “alert-2” for the “myindex” index
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
await Promise.all([
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
}),
|
||||
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
})
|
||||
]);
|
||||
---------
|
||||
|
||||
.Then you can send documents to learn which query `_percolator` queries they match
|
||||
[source,js]
|
||||
---------
|
||||
client.percolate({
|
||||
const response1 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1479,15 +1452,15 @@ client.percolate({
|
||||
title: "Foo"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
});
|
||||
|
||||
client.percolate({
|
||||
// response1 should look something like
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
|
||||
const response2 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1495,19 +1468,20 @@ client.percolate({
|
||||
title: "Foo Bar"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
// response2 should look something like
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1731,30 +1705,40 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Collect every title in the index that contains the word "test"
|
||||
[source,js]
|
||||
---------
|
||||
var allTitles = [];
|
||||
const allTitles = [];
|
||||
const responseQueue = [];
|
||||
|
||||
// first we do a search, and specify a scroll timeout
|
||||
client.search({
|
||||
// start things off by searching, setting a scroll timeout, and pushing
|
||||
// our first response into the queue to be processed
|
||||
await client.search({
|
||||
index: 'myindex',
|
||||
scroll: '30s', // keep the search results "scrollable" for 30 seconds
|
||||
source: ['title'], // filter the source to only include the title field
|
||||
q: 'title:test'
|
||||
}, function getMoreUntilDone(error, response) {
|
||||
// collect the title from each response
|
||||
})
|
||||
|
||||
while (responseQueue.length) {
|
||||
const response = responseQueue.shift();
|
||||
|
||||
// collect the titles from this response
|
||||
response.hits.hits.forEach(function (hit) {
|
||||
allTitles.push(hit._source.title);
|
||||
allTitles.push(hit.fields.title);
|
||||
});
|
||||
|
||||
if (response.hits.total > allTitles.length) {
|
||||
// ask elasticsearch for the next set of hits from this search
|
||||
client.scroll({
|
||||
// check to see if we have collected all of the titles
|
||||
if (response.hits.total === allTitles.length) {
|
||||
console.log('every "test" title', allTitles);
|
||||
break
|
||||
}
|
||||
|
||||
// get the next response if there are more titles to fetch
|
||||
responseQueue.push(
|
||||
await client.scroll({
|
||||
scrollId: response._scroll_id,
|
||||
scroll: '30s'
|
||||
}, getMoreUntilDone);
|
||||
} else {
|
||||
console.log('every "test" title', allTitles);
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
---------
|
||||
|
||||
|
||||
@ -1790,18 +1774,16 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Search with a simple query string query
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
q: 'title:test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Passing a full request definition in the Elasticsearch's Query DSL as a `Hash`
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
query: {
|
||||
@ -1817,12 +1799,11 @@ client.search({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -2043,17 +2024,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Return query terms suggestions (“auto-correction”)
|
||||
[source,js]
|
||||
---------
|
||||
client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
const response = await client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
});
|
||||
|
||||
// response will be formatted like so:
|
||||
//
|
||||
// {
|
||||
@ -2072,10 +2054,11 @@ body: {
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -2179,7 +2162,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Update document title using partial document
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2189,15 +2172,13 @@ client.update({
|
||||
title: 'Updated'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Add a tag to document `tags` property using a `script`
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2205,15 +2186,13 @@ client.update({
|
||||
script: 'ctx._source.tags += tag',
|
||||
params: { tag: 'some new tag' }
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Increment a document counter by 1 or initialize it, when the document does not exist
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '777',
|
||||
@ -2223,15 +2202,13 @@ client.update({
|
||||
counter: 1
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Delete a document if it's tagged “to-delete”
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2241,12 +2218,11 @@ client.update({
|
||||
tag: 'to-delete'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -4756,19 +4732,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform an atomic alias swap, for a rotating index
|
||||
[source,js]
|
||||
---------
|
||||
client.indices.updateAliases({
|
||||
const response = await client.indices.updateAliases({
|
||||
body: {
|
||||
actions: [
|
||||
{ remove: { index: 'logstash-2014.04', alias: 'logstash-current' } },
|
||||
{ add: { index: 'logstash-2014.05', alias: 'logstash-current' } }
|
||||
]
|
||||
}
|
||||
}).then(function (response) {
|
||||
// ...
|
||||
}, errorHandler);
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
|
||||
@ -116,26 +116,21 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get the number of all documents in the cluster
|
||||
[source,js]
|
||||
---------
|
||||
client.count(function (error, response, status) {
|
||||
// check for and handle error
|
||||
var count = response.count;
|
||||
});
|
||||
const { count } = await client.count();
|
||||
---------
|
||||
|
||||
.Get the number of documents in an index
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Get the number of documents matching a query
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name',
|
||||
body: {
|
||||
query: {
|
||||
@ -148,8 +143,6 @@ client.count({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (err, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
@ -277,7 +270,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create a document
|
||||
[source,js]
|
||||
---------
|
||||
client.create({
|
||||
await client.create({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -288,12 +281,11 @@ client.create({
|
||||
published_at: '2013-01-01',
|
||||
counter: 1
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -355,16 +347,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Delete the document `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.delete({
|
||||
await client.delete({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -420,30 +411,27 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Deleting documents with a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'myindex',
|
||||
q: 'test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Deleting documents using the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'posts',
|
||||
body: {
|
||||
query: {
|
||||
term: { published: false }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -609,20 +597,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Check that the document `/myindex/mytype/1` exist
|
||||
[source,js]
|
||||
---------
|
||||
client.exists({
|
||||
const exists = await client.exists({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, exists) {
|
||||
if (exists === true) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -735,7 +718,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.See how a document is scored against a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
// the document to test
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
@ -743,15 +726,13 @@ client.explain({
|
||||
|
||||
// the query to score it against
|
||||
q: 'field:value'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.See how a document is scored against a query written in the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -760,12 +741,11 @@ client.explain({
|
||||
match: { title: 'test' }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -909,16 +889,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.get({
|
||||
const response = await client.get({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1081,7 +1060,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create or update a document
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
const response = await client.index({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -1090,12 +1069,11 @@ client.index({
|
||||
tags: ['y', 'z'],
|
||||
published: true,
|
||||
}
|
||||
}, function (error, response) {
|
||||
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1179,7 +1157,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.An array of doc locations. Useful for getting documents from different indices.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
body: {
|
||||
docs: [
|
||||
{ _index: 'indexA', _type: 'typeA', _id: '1' },
|
||||
@ -1187,26 +1165,23 @@ client.mget({
|
||||
{ _index: 'indexC', _type: 'typeC', _id: '1' }
|
||||
]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.An array of ids. You must also specify the `index` and `type` that apply to all of the ids.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
ids: [1, 2, 3]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1289,7 +1264,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform multiple different searches, the body is made up of meta/data pairs
|
||||
[source,js]
|
||||
---------
|
||||
client.msearch({
|
||||
const response = await client.msearch({
|
||||
body: [
|
||||
// match all query, on all indices and types
|
||||
{},
|
||||
@ -1443,43 +1418,41 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.First, Register queries named “alert-1” and “alert-2” for the “myindex” index
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
await Promise.all([
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-1',
|
||||
body: {
|
||||
// This query will be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'foo'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
}),
|
||||
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
client.index({
|
||||
index: 'myindex',
|
||||
type: '.percolator',
|
||||
id: 'alert-2',
|
||||
body: {
|
||||
// This query will also be run against documents sent to percolate
|
||||
query: {
|
||||
query_string: {
|
||||
query: 'bar'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
})
|
||||
]);
|
||||
---------
|
||||
|
||||
.Then you can send documents to learn which query `_percolator` queries they match
|
||||
[source,js]
|
||||
---------
|
||||
client.percolate({
|
||||
const response1 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1487,15 +1460,15 @@ client.percolate({
|
||||
title: "Foo"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
});
|
||||
|
||||
client.percolate({
|
||||
// response1 should look something like
|
||||
// {
|
||||
// total: 1,
|
||||
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
||||
// }
|
||||
|
||||
const response2 = await client.percolate({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
@ -1503,19 +1476,20 @@ client.percolate({
|
||||
title: "Foo Bar"
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// response would equal
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
// response2 should look something like
|
||||
// {
|
||||
// total: 2,
|
||||
// matches: [
|
||||
// { _index: 'myindex', _id: 'alert-1' },
|
||||
// { _index: 'myindex', _id: 'alert-2' }
|
||||
// ]
|
||||
// }
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1743,30 +1717,40 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Collect every title in the index that contains the word "test"
|
||||
[source,js]
|
||||
---------
|
||||
var allTitles = [];
|
||||
const allTitles = [];
|
||||
const responseQueue = [];
|
||||
|
||||
// first we do a search, and specify a scroll timeout
|
||||
client.search({
|
||||
// start things off by searching, setting a scroll timeout, and pushing
|
||||
// our first response into the queue to be processed
|
||||
await client.search({
|
||||
index: 'myindex',
|
||||
scroll: '30s', // keep the search results "scrollable" for 30 seconds
|
||||
source: ['title'], // filter the source to only include the title field
|
||||
q: 'title:test'
|
||||
}, function getMoreUntilDone(error, response) {
|
||||
// collect the title from each response
|
||||
})
|
||||
|
||||
while (responseQueue.length) {
|
||||
const response = responseQueue.shift();
|
||||
|
||||
// collect the titles from this response
|
||||
response.hits.hits.forEach(function (hit) {
|
||||
allTitles.push(hit._source.title);
|
||||
allTitles.push(hit.fields.title);
|
||||
});
|
||||
|
||||
if (response.hits.total > allTitles.length) {
|
||||
// ask elasticsearch for the next set of hits from this search
|
||||
client.scroll({
|
||||
// check to see if we have collected all of the titles
|
||||
if (response.hits.total === allTitles.length) {
|
||||
console.log('every "test" title', allTitles);
|
||||
break
|
||||
}
|
||||
|
||||
// get the next response if there are more titles to fetch
|
||||
responseQueue.push(
|
||||
await client.scroll({
|
||||
scrollId: response._scroll_id,
|
||||
scroll: '30s'
|
||||
}, getMoreUntilDone);
|
||||
} else {
|
||||
console.log('every "test" title', allTitles);
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
---------
|
||||
|
||||
|
||||
@ -1802,18 +1786,16 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Search with a simple query string query
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
q: 'title:test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Passing a full request definition in the Elasticsearch's Query DSL as a `Hash`
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
query: {
|
||||
@ -1829,12 +1811,11 @@ client.search({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -2059,17 +2040,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Return query terms suggestions (“auto-correction”)
|
||||
[source,js]
|
||||
---------
|
||||
client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
const response = await client.suggest({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
mysuggester: {
|
||||
text: 'tset',
|
||||
term: {
|
||||
field: 'title'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
});
|
||||
|
||||
// response will be formatted like so:
|
||||
//
|
||||
// {
|
||||
@ -2088,10 +2070,11 @@ body: {
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
});
|
||||
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -2195,7 +2178,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Update document title using partial document
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2205,15 +2188,13 @@ client.update({
|
||||
title: 'Updated'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Add a tag to document `tags` property using a `script`
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2221,15 +2202,13 @@ client.update({
|
||||
script: 'ctx._source.tags += tag',
|
||||
params: { tag: 'some new tag' }
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Increment a document counter by 1 or initialize it, when the document does not exist
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '777',
|
||||
@ -2239,15 +2218,13 @@ client.update({
|
||||
counter: 1
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Delete a document if it's tagged “to-delete”
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -2257,12 +2234,11 @@ client.update({
|
||||
tag: 'to-delete'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -4818,19 +4794,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform an atomic alias swap, for a rotating index
|
||||
[source,js]
|
||||
---------
|
||||
client.indices.updateAliases({
|
||||
const response = await client.indices.updateAliases({
|
||||
body: {
|
||||
actions: [
|
||||
{ remove: { index: 'logstash-2014.04', alias: 'logstash-current' } },
|
||||
{ add: { index: 'logstash-2014.05', alias: 'logstash-current' } }
|
||||
]
|
||||
}
|
||||
}).then(function (response) {
|
||||
// ...
|
||||
}, errorHandler);
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
|
||||
@ -116,26 +116,21 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get the number of all documents in the cluster
|
||||
[source,js]
|
||||
---------
|
||||
client.count(function (error, response, status) {
|
||||
// check for and handle error
|
||||
var count = response.count;
|
||||
});
|
||||
const { count } = await client.count();
|
||||
---------
|
||||
|
||||
.Get the number of documents in an index
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Get the number of documents matching a query
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name',
|
||||
body: {
|
||||
query: {
|
||||
@ -148,8 +143,6 @@ client.count({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (err, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
@ -218,7 +211,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create a document
|
||||
[source,js]
|
||||
---------
|
||||
client.create({
|
||||
await client.create({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -229,12 +222,11 @@ client.create({
|
||||
published_at: '2013-01-01',
|
||||
counter: 1
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -292,16 +284,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Delete the document `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.delete({
|
||||
await client.delete({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -357,30 +348,27 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Deleting documents with a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'myindex',
|
||||
q: 'test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Deleting documents using the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'posts',
|
||||
body: {
|
||||
query: {
|
||||
term: { published: false }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -519,20 +507,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Check that the document `/myindex/mytype/1` exist
|
||||
[source,js]
|
||||
---------
|
||||
client.exists({
|
||||
const exists = await client.exists({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, exists) {
|
||||
if (exists === true) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -645,7 +628,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.See how a document is scored against a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
// the document to test
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
@ -653,15 +636,13 @@ client.explain({
|
||||
|
||||
// the query to score it against
|
||||
q: 'field:value'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.See how a document is scored against a query written in the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -670,12 +651,11 @@ client.explain({
|
||||
match: { title: 'test' }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -774,16 +754,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.get({
|
||||
const response = await client.get({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -921,7 +900,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create or update a document
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
const response = await client.index({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -930,12 +909,11 @@ client.index({
|
||||
tags: ['y', 'z'],
|
||||
published: true,
|
||||
}
|
||||
}, function (error, response) {
|
||||
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1015,7 +993,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.An array of doc locations. Useful for getting documents from different indices.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
body: {
|
||||
docs: [
|
||||
{ _index: 'indexA', _type: 'typeA', _id: '1' },
|
||||
@ -1023,26 +1001,23 @@ client.mget({
|
||||
{ _index: 'indexC', _type: 'typeC', _id: '1' }
|
||||
]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.An array of ids. You must also specify the `index` and `type` that apply to all of the ids.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
ids: [1, 2, 3]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1086,7 +1061,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform multiple different searches, the body is made up of meta/data pairs
|
||||
[source,js]
|
||||
---------
|
||||
client.msearch({
|
||||
const response = await client.msearch({
|
||||
body: [
|
||||
// match all query, on all indices and types
|
||||
{},
|
||||
@ -1374,30 +1349,40 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Collect every title in the index that contains the word "test"
|
||||
[source,js]
|
||||
---------
|
||||
var allTitles = [];
|
||||
const allTitles = [];
|
||||
const responseQueue = [];
|
||||
|
||||
// first we do a search, and specify a scroll timeout
|
||||
client.search({
|
||||
// start things off by searching, setting a scroll timeout, and pushing
|
||||
// our first response into the queue to be processed
|
||||
await client.search({
|
||||
index: 'myindex',
|
||||
scroll: '30s', // keep the search results "scrollable" for 30 seconds
|
||||
source: ['title'], // filter the source to only include the title field
|
||||
q: 'title:test'
|
||||
}, function getMoreUntilDone(error, response) {
|
||||
// collect the title from each response
|
||||
})
|
||||
|
||||
while (responseQueue.length) {
|
||||
const response = responseQueue.shift();
|
||||
|
||||
// collect the titles from this response
|
||||
response.hits.hits.forEach(function (hit) {
|
||||
allTitles.push(hit._source.title);
|
||||
allTitles.push(hit.fields.title);
|
||||
});
|
||||
|
||||
if (response.hits.total > allTitles.length) {
|
||||
// ask elasticsearch for the next set of hits from this search
|
||||
client.scroll({
|
||||
// check to see if we have collected all of the titles
|
||||
if (response.hits.total === allTitles.length) {
|
||||
console.log('every "test" title', allTitles);
|
||||
break
|
||||
}
|
||||
|
||||
// get the next response if there are more titles to fetch
|
||||
responseQueue.push(
|
||||
await client.scroll({
|
||||
scrollId: response._scroll_id,
|
||||
scroll: '30s'
|
||||
}, getMoreUntilDone);
|
||||
} else {
|
||||
console.log('every "test" title', allTitles);
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
---------
|
||||
|
||||
|
||||
@ -1433,18 +1418,16 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Search with a simple query string query
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
q: 'title:test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Passing a full request definition in the Elasticsearch's Query DSL as a `Hash`
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
query: {
|
||||
@ -1460,12 +1443,11 @@ client.search({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1750,7 +1732,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Update document title using partial document
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -1760,15 +1742,13 @@ client.update({
|
||||
title: 'Updated'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Add a tag to document `tags` property using a `script`
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -1776,15 +1756,13 @@ client.update({
|
||||
script: 'ctx._source.tags += tag',
|
||||
params: { tag: 'some new tag' }
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Increment a document counter by 1 or initialize it, when the document does not exist
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '777',
|
||||
@ -1794,15 +1772,13 @@ client.update({
|
||||
counter: 1
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Delete a document if it's tagged “to-delete”
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -1812,12 +1788,11 @@ client.update({
|
||||
tag: 'to-delete'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -4363,19 +4338,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform an atomic alias swap, for a rotating index
|
||||
[source,js]
|
||||
---------
|
||||
client.indices.updateAliases({
|
||||
const response = await client.indices.updateAliases({
|
||||
body: {
|
||||
actions: [
|
||||
{ remove: { index: 'logstash-2014.04', alias: 'logstash-current' } },
|
||||
{ add: { index: 'logstash-2014.05', alias: 'logstash-current' } }
|
||||
]
|
||||
}
|
||||
}).then(function (response) {
|
||||
// ...
|
||||
}, errorHandler);
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
|
||||
@ -116,26 +116,21 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get the number of all documents in the cluster
|
||||
[source,js]
|
||||
---------
|
||||
client.count(function (error, response, status) {
|
||||
// check for and handle error
|
||||
var count = response.count;
|
||||
});
|
||||
const { count } = await client.count();
|
||||
---------
|
||||
|
||||
.Get the number of documents in an index
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Get the number of documents matching a query
|
||||
[source,js]
|
||||
---------
|
||||
client.count({
|
||||
const { count } = await client.count({
|
||||
index: 'index_name',
|
||||
body: {
|
||||
query: {
|
||||
@ -148,8 +143,6 @@ client.count({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (err, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
@ -218,7 +211,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create a document
|
||||
[source,js]
|
||||
---------
|
||||
client.create({
|
||||
await client.create({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -229,12 +222,11 @@ client.create({
|
||||
published_at: '2013-01-01',
|
||||
counter: 1
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -292,16 +284,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Delete the document `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.delete({
|
||||
await client.delete({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -357,30 +348,27 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Deleting documents with a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'myindex',
|
||||
q: 'test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Deleting documents using the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.deleteByQuery({
|
||||
await client.deleteByQuery({
|
||||
index: 'posts',
|
||||
body: {
|
||||
query: {
|
||||
term: { published: false }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -519,20 +507,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Check that the document `/myindex/mytype/1` exist
|
||||
[source,js]
|
||||
---------
|
||||
client.exists({
|
||||
const exists = await client.exists({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, exists) {
|
||||
if (exists === true) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -645,7 +628,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.See how a document is scored against a simple query
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
// the document to test
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
@ -653,15 +636,13 @@ client.explain({
|
||||
|
||||
// the query to score it against
|
||||
q: 'field:value'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.See how a document is scored against a query written in the Query DSL
|
||||
[source,js]
|
||||
---------
|
||||
client.explain({
|
||||
const response = await client.explain({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -670,12 +651,11 @@ client.explain({
|
||||
match: { title: 'test' }
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -774,16 +754,15 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Get `/myindex/mytype/1`
|
||||
[source,js]
|
||||
---------
|
||||
client.get({
|
||||
const response = await client.get({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: 1
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -921,7 +900,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Create or update a document
|
||||
[source,js]
|
||||
---------
|
||||
client.index({
|
||||
const response = await client.index({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -930,12 +909,11 @@ client.index({
|
||||
tags: ['y', 'z'],
|
||||
published: true,
|
||||
}
|
||||
}, function (error, response) {
|
||||
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1015,7 +993,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.An array of doc locations. Useful for getting documents from different indices.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
body: {
|
||||
docs: [
|
||||
{ _index: 'indexA', _type: 'typeA', _id: '1' },
|
||||
@ -1023,26 +1001,23 @@ client.mget({
|
||||
{ _index: 'indexC', _type: 'typeC', _id: '1' }
|
||||
]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.An array of ids. You must also specify the `index` and `type` that apply to all of the ids.
|
||||
[source,js]
|
||||
---------
|
||||
client.mget({
|
||||
const response = await client.mget({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
body: {
|
||||
ids: [1, 2, 3]
|
||||
}
|
||||
}, function(error, response){
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1086,7 +1061,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform multiple different searches, the body is made up of meta/data pairs
|
||||
[source,js]
|
||||
---------
|
||||
client.msearch({
|
||||
const response = await client.msearch({
|
||||
body: [
|
||||
// match all query, on all indices and types
|
||||
{},
|
||||
@ -1374,30 +1349,40 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Collect every title in the index that contains the word "test"
|
||||
[source,js]
|
||||
---------
|
||||
var allTitles = [];
|
||||
const allTitles = [];
|
||||
const responseQueue = [];
|
||||
|
||||
// first we do a search, and specify a scroll timeout
|
||||
client.search({
|
||||
// start things off by searching, setting a scroll timeout, and pushing
|
||||
// our first response into the queue to be processed
|
||||
await client.search({
|
||||
index: 'myindex',
|
||||
scroll: '30s', // keep the search results "scrollable" for 30 seconds
|
||||
source: ['title'], // filter the source to only include the title field
|
||||
q: 'title:test'
|
||||
}, function getMoreUntilDone(error, response) {
|
||||
// collect the title from each response
|
||||
})
|
||||
|
||||
while (responseQueue.length) {
|
||||
const response = responseQueue.shift();
|
||||
|
||||
// collect the titles from this response
|
||||
response.hits.hits.forEach(function (hit) {
|
||||
allTitles.push(hit._source.title);
|
||||
allTitles.push(hit.fields.title);
|
||||
});
|
||||
|
||||
if (response.hits.total > allTitles.length) {
|
||||
// ask elasticsearch for the next set of hits from this search
|
||||
client.scroll({
|
||||
// check to see if we have collected all of the titles
|
||||
if (response.hits.total === allTitles.length) {
|
||||
console.log('every "test" title', allTitles);
|
||||
break
|
||||
}
|
||||
|
||||
// get the next response if there are more titles to fetch
|
||||
responseQueue.push(
|
||||
await client.scroll({
|
||||
scrollId: response._scroll_id,
|
||||
scroll: '30s'
|
||||
}, getMoreUntilDone);
|
||||
} else {
|
||||
console.log('every "test" title', allTitles);
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
---------
|
||||
|
||||
|
||||
@ -1433,18 +1418,16 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Search with a simple query string query
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
q: 'title:test'
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Passing a full request definition in the Elasticsearch's Query DSL as a `Hash`
|
||||
[source,js]
|
||||
---------
|
||||
client.search({
|
||||
const response = await client.search({
|
||||
index: 'myindex',
|
||||
body: {
|
||||
query: {
|
||||
@ -1460,12 +1443,11 @@ client.search({
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -1750,7 +1732,7 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Update document title using partial document
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -1760,15 +1742,13 @@ client.update({
|
||||
title: 'Updated'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Add a tag to document `tags` property using a `script`
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -1776,15 +1756,13 @@ client.update({
|
||||
script: 'ctx._source.tags += tag',
|
||||
params: { tag: 'some new tag' }
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
.Increment a document counter by 1 or initialize it, when the document does not exist
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '777',
|
||||
@ -1794,15 +1772,13 @@ client.update({
|
||||
counter: 1
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
})
|
||||
---------
|
||||
|
||||
.Delete a document if it's tagged “to-delete”
|
||||
[source,js]
|
||||
---------
|
||||
client.update({
|
||||
const response = await client.update({
|
||||
index: 'myindex',
|
||||
type: 'mytype',
|
||||
id: '1',
|
||||
@ -1812,12 +1788,11 @@ client.update({
|
||||
tag: 'to-delete'
|
||||
}
|
||||
}
|
||||
}, function (error, response) {
|
||||
// ...
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
@ -4398,19 +4373,18 @@ Check the *<<api-conventions>>* and https://www.elastic.co/guide/en/elasticsearc
|
||||
.Perform an atomic alias swap, for a rotating index
|
||||
[source,js]
|
||||
---------
|
||||
client.indices.updateAliases({
|
||||
const response = await client.indices.updateAliases({
|
||||
body: {
|
||||
actions: [
|
||||
{ remove: { index: 'logstash-2014.04', alias: 'logstash-current' } },
|
||||
{ add: { index: 'logstash-2014.05', alias: 'logstash-current' } }
|
||||
]
|
||||
}
|
||||
}).then(function (response) {
|
||||
// ...
|
||||
}, errorHandler);
|
||||
});
|
||||
---------
|
||||
|
||||
|
||||
|
||||
*Params*
|
||||
|
||||
[horizontal]
|
||||
|
||||
@ -3664,6 +3664,7 @@ api.indices.prototype.getMapping = ca({
|
||||
* Perform a [indices.getSettings](https://www.elastic.co/guide/en/elasticsearch/reference/6.x/indices-get-settings.html) request
|
||||
*
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {<<api-param-type-duration-string,`DurationString`>>} params.masterTimeout - Specify timeout for connection to master
|
||||
* @param {<<api-param-type-boolean,`Boolean`>>} params.ignoreUnavailable - Whether specified concrete indices should be ignored when unavailable (missing or closed)
|
||||
* @param {<<api-param-type-boolean,`Boolean`>>} params.allowNoIndices - Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
|
||||
* @param {<<api-param-type-string,`String`>>} [params.expandWildcards=open,closed] - Whether to expand wildcard expression to concrete indices that are open, closed or both.
|
||||
@ -3675,6 +3676,10 @@ api.indices.prototype.getMapping = ca({
|
||||
*/
|
||||
api.indices.prototype.getSettings = ca({
|
||||
params: {
|
||||
masterTimeout: {
|
||||
type: 'time',
|
||||
name: 'master_timeout'
|
||||
},
|
||||
ignoreUnavailable: {
|
||||
type: 'boolean',
|
||||
name: 'ignore_unavailable'
|
||||
|
||||
Reference in New Issue
Block a user