️ 이 클라이언트는 더 이상 사용되지 않습니다.️ Enterprise Search 버전 8.3.2부터 사용자를 새로운 Enterprise Search 노드 클라이언트로 안내하고 이 클라이언트를 더 이상 사용하지 않습니다.
이 프로젝트에 대한 우리의 개발 노력은 버그 수정으로 제한됩니다. 향후 모든 개선 사항은 엔터프라이즈 검색 노드 클라이언트에 중점을 둘 것입니다.
감사합니다! - 탄성
Elastic App Search를 통해 우수하고 관련성 높은 검색 경험을 구축하기 위한 자사 Node.JS 클라이언트입니다.
이 패키지를 설치하려면 다음을 실행하세요.
npm install @elastic/app-search-node
이 클라이언트는 App Search와 함께 버전이 지정되고 출시됩니다.
호환성을 보장하려면 해당 App Search 구현의 주요 버전 내에서 이 라이브러리의 최신 버전을 사용하세요.
예를 들어 App Search 7.3
의 경우 이 라이브러리의 7.3
이상을 사용하고 8.0
은 사용하지 마세요.
App Search의 Swiftype.com에서 제공되는 SaaS 버전을 사용하는 경우 클라이언트 버전 7.5.x를 사용해야 합니다.
이 클라이언트를 사용하는 것은 Elastic App Search 인스턴스가 이미 실행 중이라고 가정합니다.
클라이언트는 baseUrlFn
및 apiKey
매개변수를 사용하여 구성됩니다.
const apiKey = 'private-mu75psc5egt9ppzuycnc2mc3'
const baseUrlFn = ( ) => 'http://localhost:3002/api/as/v1/'
const client = new AppSearchClient ( undefined , apiKey , baseUrlFn )
메모:
[apiKey]
는 API에 대한 요청을 인증합니다. 클라이언트에서는 모든 키 유형을 사용할 수 있지만 각 키 유형의 범위는 다릅니다. 키에 대한 자세한 내용은 설명서를 확인하세요.
App Search의 Swiftype.com에서 제공되는 SaaS 버전을 사용하는 경우 baseUrlFn
매개변수 대신 hostIdentifier
사용하여 클라이언트를 구성할 수 있습니다. hostIdentifier
자격 증명 메뉴에서 찾을 수 있습니다.
const AppSearchClient = require ( '@elastic/app-search-node' )
const hostIdentifier = 'host-c5s2mj'
const apiKey = 'private-mu75psc5egt9ppzuycnc2mc3'
const client = new AppSearchClient ( hostIdentifier , apiKey )
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 ) )
const engineName = 'favorite-videos'
client
. getSchema ( engineName )
. then ( response => console . log ( response ) )
. catch ( error => console . log ( error . errorMessages ) )
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 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 Search 인스턴스에서 기록할 실제 유효한 값으로 재정의합니다.API_KEY
- 테스트에 사용된 가짜 값을 App Search 인스턴스에서 기록할 실제 유효한 값으로 재정의하는 데 사용합니다.REPLAY=record
- 아직 존재하지 않는 경우 새 응답을 녹음하도록 재생에 지시합니다.npm run test
- 테스트 실행-- -g 'should create a meta engine'
- 생성한 새 테스트만 실행하도록 테스트를 제한합니다. 예를 들어 '메타 엔진을 생성해야 합니다'이렇게 하면 새 고정 장치가 생성됩니다. 해당 고정 장치에 기록된 호스트 식별자와 API 키를 테스트에서 사용하는 값으로 바꾸려면 해당 고정 장치를 수동으로 편집해야 합니다.
또한 사용된 호스트에 따라 fixtures
아래의 올바른 이름의 디렉토리에 Fixture가 있는지 확인해야 합니다.
npm run test
실행할 때 다음과 같은 오류가 발생하면 오류가 발생하므로 뭔가 잘못된 것인지 알 수 있습니다.
Error: POST https://host-c5s2mj.api.swiftype.com:443/api/as/v1/engines refused: not recording and no network access
예상대로 작동하지 않는 경우 문제를 열어주세요.
가장 좋은 방법은 설명서를 읽는 것입니다.
Elastic App Search 커뮤니티 토론 포럼을 확인해 보세요.
우리는 프로젝트에 참여하는 분들을 환영합니다. 시작하기 전에 몇 가지 참고 사항이 있습니다.
아파치 2.0 © 탄력적
모든 기여자에게 감사드립니다!