此客户端已贬值
企业搜索版8.3.2,我们正引导用户到新的 企业搜索节点客户端 财务报告和审定财务报表 贬取此客户端.
这个项目的开发工作将仅限于修复错误. 今后所有的增强都将以企业搜索节点客户端为重点.
谢谢! - 有弹性

用于构建优秀相关搜索经验的首发方Node.JS客户端 弹性 App 搜索。 。 。 .
目录
开始 QQ
要安装此软件包, 请运行 :
npm install @elastic/app-search-node
版本
这个客户端在App Search同时被版本并发布.
为保证相容性,在相应的App Search执行的主要版本中使用此库的最新版本.
例如, App 搜索 7.3,使用时 7.3 本图书馆或以上,但不是 8.0。 。 。 .
如果你正在使用 SaaS 版本可在sourkype.com上查阅 app Search中,您应当使用客户端的7.5.x版本.
使用量
设置: 配置客户端和认证
使用此客户端假设您已有实例 弹性 App 搜索 继续跑.
客户端使用 baseUrlFn 财务报告和审定财务报表 apiKey 参数.
const apiKey = 'private-mu75psc5egt9ppzuycnc2mc3'
const baseUrlFn = () => 'http://localhost:3002/api/as/v1/'
const client = new AppSearchClient(undefined, apiKey, baseUrlFn)
说明:
这个 [apiKey] 认证请求到 API .
您可以与客户端使用任意密钥类型, 但每个类型都有不同的范围 .
关于密钥的更多信息,请查看 文档。 。 。 .
Swiftype.com App搜索用户 :
使用时 SaaS 版本可在sourkype.com上查阅 在 App 搜索中,您可以使用您的 hostIdentifier 代替 baseUrlFn 参数.
这个 hostIdentifier 可在 全权证书 菜单.
const AppSearchClient = require('@elastic/app-search-node')
const hostIdentifier = 'host-c5s2mj'
const apiKey = 'private-mu75psc5egt9ppzuycnc2mc3'
const client = new AppSearchClient(hostIdentifier, apiKey)
API 方法
索引:创建或替换文档
const engineName = 'favorite-videos'
const documents = [
{
id: 'INscMGmhmX4',
url: 'https://www.youtube.com/watch?v=INscMGmhmX4',
title: 'The Original Grumpy Cat',
body: 'A wonderful video of a magnificent cat.'
},
{
id: 'JNDFojsd02',
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
title: 'Another Grumpy Cat',
body: 'A great video of another cool cat.'
}
]
client
.indexDocuments(engineName, documents)
.then(response => console.log(response))
.catch(error => console.log(error))
注意此 API 将不会丢入索引错误 。 每个文档的响应正文中包含错误:
[
{ "id": "park_rocky-mountain", "errors": [] },
{
"id": "park_saguaro",
"errors": ["Invalid field value: Value 'foo' cannot be parsed as a float"]
}
]
索引:更新文档(部分更新)
const engineName = 'favorite-videos'
const documents = [
{
id: 'INscMGmhmX4',
title: 'Updated title'
}
]
client
.updateDocuments(engineName, documents)
.then(response => console.log(response))
.catch(error => console.log(error))
获取文档
const engineName = 'favorite-videos'
const documentIds = ['INscMGmhmX4', 'JNDFojsd02']
client
.getDocuments(engineName, documentIds)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
列出文档
const engineName = 'favorite-videos'
// Without paging
client
.listDocuments(engineName)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
// With paging
client
.listDocuments(engineName, { page: { size: 10, current: 1 } })
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
销毁文档
const engineName = 'favorite-videos'
const documentIds = ['INscMGmhmX4', 'JNDFojsd02']
client
.destroyDocuments(engineName, documentIds)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
列出引擎
client
.listEngines({ page: { size: 10, current: 1 } })
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
获取引擎
const engineName = 'favorite-videos'
client
.getEngine(engineName)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
创建引擎
const engineName = 'favorite-videos'
client
.createEngine(engineName, { language: 'en' })
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
正在摧毁引擎
const engineName = 'favorite-videos'
client
.destroyEngine(engineName)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
搜索中
const engineName = 'favorite-videos'
const query = 'cat'
const searchFields = { title: {} }
const resultFields = { title: { raw: {} } }
const options = { search_fields: searchFields, result_fields: resultFields }
client
.search(engineName, query, options)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
多搜索器
const engineName = 'favorite-videos'
const searches = [
{ query: 'cat', options: {
search_fields: { title: {} },
result_fields: { title: { raw: {} } }
} },
{ query: 'grumpy', options: {} }
]
client
.multiSearch(engineName, searches)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
查询建议
const engineName = 'favorite-videos'
const options = {
size: 3,
types: {
documents: {
fields: ['title']
}
}
}
client
.querySuggestion(engineName, 'cat', options)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
列出限制
const engineName = 'favorite-videos'
client
.listCurations(engineName)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
// Pagination details are optional
const paginationDetails = {
page: {
current: 2,
size: 10
}
}
client
.listCurations(engineName, paginationDetails)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
获取校正
const engineName = 'favorite-videos'
const curationId = 'cur-7438290'
client
.getCuration(engineName, curationId)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
创建曲线
const engineName = 'favorite-videos'
const newCuration = {
queries: ['cat blop'],
promoted: ['Jdas78932'],
hidden: ['INscMGmhmX4', 'JNDFojsd02']
}
client
.createCuration(engineName, newCuration)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
更新曲线
const engineName = 'favorite-videos'
const curationId = 'cur-7438290'
// "queries" is required, either "promoted" or "hidden" is required.
// Values sent for all fields will overwrite existing values.
const newDetails = {
queries: ['cat blop'],
promoted: ['Jdas78932', 'JFayf782']
}
client
.updateCuration(engineName, curationId, newDetails)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
删除限制
const engineName = 'favorite-videos'
const curationId = 'cur-7438290'
client
.destroyCuration(engineName, curationId)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
获取Schemas
const engineName = 'favorite-videos'
client
.getSchema(engineName)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
更新 Schemas
const engineName = 'favorite-videos'
const schema = {
views: 'number',
created_at: 'date'
}
client
.updateSchema(engineName, schema)
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
创建已签名的搜索密钥
创建只返回标题字段的搜索密钥 .
const publicSearchKey = 'search-xxxxxxxxxxxxxxxxxxxxxxxx'
// This name must match the name of the key above from your App Search dashboard
const publicSearchKeyName = 'search-key'
const enforcedOptions = {
result_fields: { title: { raw: {} } },
filters: { world_heritage_site: 'true' }
}
// Optional. See https://github.com/auth0/node-jsonwebtoken#usage for all options
const signOptions = {
expiresIn: '5 minutes'
}
const signedSearchKey = AppSearchClient.createSignedSearchKey(
publicSearchKey,
publicSearchKeyName,
enforcedOptions,
signOptions
)
const baseUrlFn = () => 'http://localhost:3002/api/as/v1/'
const client = new AppSearchClient(undefined, signedSearchKey, baseUrlFn)
client.search('sample-engine', 'everglade')
创建元引擎
const engineName = 'my-meta-engine'
client
.createMetaEngine(engineName, ['source-engine-1', 'source-engine-2'])
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
在元引擎中添加源引擎
const engineName = 'my-meta-engine'
client
.addMetaEngineSources(engineName, ['source-engine-3'])
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
从元引擎中删除源引擎
const engineName = 'my-meta-engine'
client
.deleteMetaEngineSources(engineName, ['source-engine-3'])
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
创建引擎
const engineName = 'my-meta-engine'
client
.createEngine(engineName, {
type: 'meta',
source_engines: ['source-engine-1', 'source-engine-2']
})
.then(response => console.log(response))
.catch(error => console.log(error.errorMessages))
对于此客户端中没有的 App 搜索 API
我们试图让这个客户端随时更新App Search中所有可用的API端点.
还有一些API可能还没有提供. 对于这些API,请使用低等客户端连接到任何App Search端点.
const engineName = 'favorite-videos'
const options = {
query: 'cats'
}
const Client = require('@elastic/app-search-node/lib/client')
const client = new Client('private-mu75psc5egt9ppzuycnc2mc3', 'http://localhost:3002/api/as/v1/')
client.post(`engines/${encodeURIComponent(engineName)}/search`, options).then(console.log)
正在测试
npm test
此工程的规格 节点重放 获取固定装置.
应该从正在运行的 App Search 实例中捕获新的固定装置.
为了捕捉出新的固定装置,运行如下命令:
nvm use
HOST_IDENTIFIER=host-c5s2mj API_KEY=private-b94wtaoaym2ovdk5dohj3hrz REPLAY=record npm run test -- -g 'should create a meta engine'
要打破这一点一点点...
HOST_IDENTIFIER- 使用此选项来覆盖测试中使用的假值, 并带有实际有效的值, 用于您的 App 搜索实例以记录来自API_KEY- 使用此选项来覆盖测试中使用的假值, 并带有实际有效的值, 用于您的 App 搜索实例以记录来自REPLAY=record- 告诉重播,如果一个新的回应不存在的话npm run test- 进行测试-- -g 'should create a meta engine'- 将测试限制在只运行您创建的新测试, 例如“ 应创建元引擎 ”
这将创建一个新的固定符, 确保您手动编辑该固定符以替换主机标识符和 api 密钥 记录在测试所用的值上.
您还需要确保固定在正确命名的目录中 fixtures 根据被使用的主机.
你会知道,如果有什么不对 因为这样会出错 当你运行 npm run test 错误如:
Error: POST https://host-c5s2mj.api.swiftype.com:443/api/as/v1/engines refused: not recording and no network access
问 题
我在哪里报告与客户的问题?
如果有东西不起作用,请打开 问题。 。 。 .
哪里可以多学点App Search?
你最好的赌注是读 文档。 。 。 .
我还能去哪找人帮忙?
你可以去检查 弹性 App 搜索社区讨论论坛。 。 。 .
贡献
我们欢迎该项目的捐助者。 在你开始前, 几个笔记...
- 在启动拉动请求前,请创建一个问题 讨论您提案的范围。 。 。 .
- 请酌情写出简单的代码和简明文档.
许可证 QQ
谢谢大家 捐助者来啊!