concrete index
the name of alias
attachAndDetachAlias attach and detach alias in one request, used to smoothly convert indexes within one alias
index to attach
index to detach
the name of alias
delete multiple documents in the specified index
the specify index name
array of doc ids to be deleted
import * as es from 'es'; let esclient = es.newClient('esconnect')
let indexName1 = "my_testIndex"
// 创建父索引question,映射子索引answer let m = { "properties": { "my_join_field": { "type": "join", // 指定这是一个父子文档 "relations": { // 设置父子关系 "question": "answer" // question是父文档,answer是子文档 } } } } esclient.createIndexWithMapping("my_testIndex", m)
// 插入父文档数据 let doc = { "_id": "1", // 父文档ID,这里举例为1 "text": "This is a question", // 本样例的父文档只有一个属性字段text "my_join_field": { "name": "question" // 指明是question父文档 } } esclient.indexDoc('my_testIndex', doc) // 插入一条数据,普通的indexDoc插入接口 esclient.refresh('my_testIndex') // 新增数据后刷新索引后可查看
let docs = [] for (let i = 0; i < 3; i++) { //批量创建数据, docs.push({ // "_id": (i).toString(), // 子文档ID,不写时是个随机数 "text": "This is an answer" + i.toString(), // 子文档内容,同样也只能写一个字段text "my_join_field": { "name": "answer", // 指明这是answer子文档; "parent": "1" // 指明其父文档的 Id; } }) } esclient.bulkIndexChildDocs(indexName1, "1",docs) // 批量插入,结果将是一个question对应多个answer的索引
insert or full-doc update multiple documents in the specified index Notice: if one doc contains field "_id", the value will be used as self-defined Doc ID, "_id" itself will not be stored in to search engine If document with self-defined Doc ID is already exist, this operation will perform a full-doc update, otherwise, insert the document with self-defined Doc ID If no "_id" specified, document will be inserted with a random Doc ID.
cat show indexes basic information
basic info for each index, for example:
[
{
"IndexName": "foo",
"Aliases": null,
"DocCount": 2
} {
"IndexName": "bar",
"Aliases": [
"a"
],
"DocCount": 0
}
]
check if document is existing
check whether the specified index is existing
boolean true for exist, otherwise false
clear scrollID
游标查询三个接口:scrollSearch,scrollIDSearch,clearScroll 需一起用,详细用例见scrollSearch
count documents in an index
documents count
count documents by dsl
condition in ES dsl format
documents count
count documents by light-weight query string
light-weight query string
documents count
create a new index
create a new index with mapping
delete documents by query
deleted count
delete a document by document id
docID is got by search or query interface, which is named as _id
.
see the query interface for more details
the specify index
the specify document id
detachAlias detach concrete index with alias
concrete index
the name of alias
delete an index. Notice: cannot delete alias directly
the index to be dropped
input index name return associated aliases
associated aliases
get all indexes for the current tenant
index name list
get attached concrete indexes by alias
the index name which created in connector
attached indexes
get one document by document id
the specify index
the specify document id
document the doc
getMapping get mapping for an index or alias
import * as es from 'es'; let esclient = es.newClient('esconnect')
let indexName1 = "my_testIndex"
// 创建父索引question,映射子索引answer let m = { "properties": { "my_join_field": { "type": "join", // 指定这是一个父子文档 "relations": { // 设置父子关系 "question": "answer" // question是父文档,answer是子文档 } } } } esclient.createIndexWithMapping("my_testIndex", m)
// 插入父文档数据 let doc = { "_id": "1", // 父文档ID,这里举例为1 "text": "This is a question", // 本样例的父文档只有一个属性字段text "my_join_field": { "name": "question" // 指明是question父文档 } } esclient.indexDoc('my_testIndex', doc) // 插入一条数据,普通的indexDoc插入接口 esclient.refresh('my_testIndex') // 新增数据后刷新索引后可查看
// 插入一条子文档数据 let routeDoc = { "_id": "5", // 不写时会是个随机数 "text": "This is an answer1", "my_join_field": { "name": "answer", // 指明这是answer子文档; "parent": "1" // 指明其父文档的 Id; } } esclient.indexChildDoc('my_testIndex', "1", routeDoc) esclient.refresh('my_testIndex')
insert or fully update a document in the specified index Notice: if doc contains field "_id", the value will be used as self-defined Doc ID, "_id" itself will not be stored in to search engine If document with self-defined Doc ID is already exist, this operation will perform a full-doc update, otherwise, insert the document with self-defined Doc ID If no "_id" specified, document will be inserted with a random Doc ID.
the specify index
the document to be indexed.
inserted document id
provides light-weight querying. You can use *
to match zero or more characters
传参如: "foo", "foo:bar", "foo:bar AND qux:baz".
true时默认最多返回5000条数据,可改osql的elasticsearch_querydocs_size值(最多10万)返回更多, 如果还需要更多数据,建议用scrollSearch接口, false时返回10条数据。
可以传入多个索引名。如果没有传入indexName,则搜索所有索引。
已创建文档数组。例如:
[
{
"_id": "fGGoNGoBvz7NQ98rl2Sn",
"_index": "user-defined-index-name",
"field1": "apple",
"field2": "orange"
},
{
"_id": "CTZiOGoBZQ34Z4YeRxSv",
"_index": "user-defined-index-name",
"field1": "banana",
"field2": "coconut"
}
]
make documents in specified index available for search immediately 每次索引的数据发生增删改后,可以选择手动刷新索引,使变化内容立即可被搜索到(否则会等约1秒时间)
Notice: This operation is resource-intensive. To ensure good performance, recommend to wait for periodic refresh(usually 1s) rather than performing an explicit refresh when possible. 重要: 当写测试的时候,手动刷新或许有用,但在生产环境下每次增删改一个文档就调用refresh函数会产生很大的性能开销 不用担心更新的数据无法被搜索,通常集群会在1秒钟内自动进行刷新。所以在开发时请意识到 Elasticsearch 的近实时搜索的特性,并接受它的不足 仅仅在非常需要进行实时搜索的情况下,再选择调用refresh接口
reindex copy old index to new index
search records using scrollID, use after scrollSearch
游标查询三个接口:scrollSearch,scrollIDSearch,clearScroll 需一起用,详细用例见scrollSearch
first scrollSearch records
游标查询三个接口:scrollSearch,scrollIDSearch,clearScroll 需一起用
matched list, scrollID, matched documents count
get documents by provided JSON DSL condition
the condition
the specify indexes, if no index is provided then all indexes will be searched
retrieved documents and total hits. For example,
"hits": {
[
{
"_id": "Z77z1GoBFqkjW4TNVqT9",
"_index": "0000000000kmfw1lhyz7:myindex1",
"_score": 1,
"_source": {
"age": 50,
"name": {
"first_name": "foo",
"last_name": "bar"
}
},
"_type": "t"
}
],
"max_score": 1,
"total": 1
}
search by dsl condition and only return matched document id list
the specify index
the condition
matched id list
update documents by query
the specify index
condition dsl. You can run the query type command to create a DSL.
groovy script
updated count
partly update a document by given data
the specify index
id of document to be updated
the data use for update
attach concrete index with alias