本文整理匯總了TypeScript中elasticsearch.Client.search方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Client.search方法的具體用法?TypeScript Client.search怎麽用?TypeScript Client.search使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類elasticsearch.Client
的用法示例。
在下文中一共展示了Client.search方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: search
/*
search(value): Promise<SearchResponse<any>> {
if (value) {
console.log(value)
return this._client.search({
index: 'blog',
q: `title:${value}`
})
} else {
return Promise.resolve({})
}
}
addToIndex(value): Promise<any> {
return this._client.create(value)
}
isAvailable(): Promise<any> {
return this._client.ping({
requestTimeout: Infinity,
hello: "elasticsearch!"
});
}*/
search(value): any {
if (value) {
console.log(value)
return this._client.search({
index: 'blog',
q: `title:${value}`
})
} else {
return Promise.resolve({})
}
}
示例2: search
search(value): Observable<any> {
if (value) {
console.log(value)
var client = new elasticsearch.Client({
host: 'http://localhost:9200',
log: 'trace'
});
return Observable.fromPromise(client.search({
index: 'blog',
q: `title:${value}`
}))
}else{
return Observable.of({})
}
}
示例3:
client = new elasticsearch.Client({
hosts: [
'box1.server.org',
'box2.server.org'
],
selector: (hosts: any) => { }
});
client.ping({
requestTimeout: 30000
}, (error) => {
});
client.search({
q: 'pants'
}).then((body) => {
const hits = body.hits.hits;
}, (error) => {
});
client.indices.delete({
index: 'test_index',
ignore: [404]
}).then((body) => {
}, (error) => {
});
client.deleteByQuery({
index: 'test_index',
type: 'test_type',
示例4: require
/// <reference path="type_declarations/index.d.ts" />
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host: 'localhost:9200',
log: 'info'
});
client.search({
index: 'acl',
type: 'bib',
size: 20,
body: {
query: {
match: {
_all: 'twitter'
}
}
}
}, function(err, response) {
if (err) throw err;
var result = response.hits;
console.log('Showing %d/%d results', result.hits.length, result.total);
var result_json = JSON.stringify(result, null, ' ');
console.log('search result: %s', result_json);
process.exit();
});