️ تم إهمال هذا العميل️ اعتبارًا من الإصدار 8.3.2 من Enterprise Search، نقوم بتوجيه المستخدمين إلى Enterprise Search Node Client الجديد وإهمال هذا العميل.
ستقتصر جهودنا التطويرية في هذا المشروع على إصلاحات الأخطاء. ستركز كافة التحسينات المستقبلية على Enterprise Search Node Client.
شكرًا لك! - مطاطا
عميل Node.JS من الطرف الأول لبناء تجارب بحث ممتازة وذات صلة باستخدام Elastic App Search.
لتثبيت هذه الحزمة، قم بتشغيل:
npm install @elastic/app-search-node
تم إصدار هذا العميل وإصداره جنبًا إلى جنب مع App Search.
لضمان التوافق، استخدم أحدث إصدار من هذه المكتبة ضمن الإصدار الرئيسي لتطبيق App Search المطابق.
على سبيل المثال، بالنسبة لـ App Search 7.3
، استخدم 7.3
من هذه المكتبة أو أعلى، ولكن ليس 8.0
.
إذا كنت تستخدم إصدار SaaS المتوفر على Swiftype.com من App Search، فيجب عليك استخدام الإصدار 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]
بمصادقة الطلبات إلى واجهة برمجة التطبيقات. يمكنك استخدام أي نوع مفتاح مع العميل، ولكن لكل نوع نطاق مختلف. لمزيد من المعلومات حول المفاتيح، راجع الوثائق.
عند استخدام إصدار SaaS المتوفر على Swiftype.com من App Search، يمكنك تكوين العميل باستخدام hostIdentifier
بدلاً من المعلمة baseUrlFn
. يمكن العثور على 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 ) )
لاحظ أن واجهة برمجة التطبيقات هذه لن تؤدي إلى حدوث خطأ في الفهرسة. يتم تضمين الأخطاء في نص الاستجابة لكل مستند:
[
{ "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 ) )
نحن نحاول إبقاء هذا العميل على اطلاع دائم بجميع نقاط نهاية واجهة برمجة التطبيقات المتاحة من خلال بحث التطبيقات.
هناك عدد قليل من واجهات برمجة التطبيقات التي قد لا تكون متاحة بعد. بالنسبة لواجهات برمجة التطبيقات هذه، يرجى استخدام العميل منخفض المستوى للاتصال للوصول إلى أي نقطة نهاية لبحث التطبيقات.
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
- استخدم هذا لتجاوز القيمة المزيفة المستخدمة في الاختبارات بقيمة صالحة فعلية لمثيل بحث التطبيق الخاص بك للتسجيل منهAPI_KEY
- استخدم هذا لتجاوز القيمة المزيفة المستخدمة في الاختبارات بقيمة صالحة فعلية لمثيل بحث التطبيق الخاص بك للتسجيل منهREPLAY=record
- يخبر إعادة التشغيل بتسجيل استجابة جديدة إذا لم تكن موجودة بالفعلnpm run test
- قم بتشغيل الاختبارات-- -g 'should create a meta engine'
- قم بقصر الاختبارات على تشغيل الاختبار الجديد الذي قمت بإنشائه فقط، "يجب إنشاء محرك تعريف" على سبيل المثالسيؤدي هذا إلى إنشاء تثبيت جديد، وتأكد من تحرير هذا التثبيت يدويًا لاستبدال معرف المضيف ومفتاح واجهة برمجة التطبيقات المسجل في هذا التثبيت بالقيم التي تستخدمها الاختبارات.
ستحتاج أيضًا إلى التأكد من وجود التركيب في الدليل المسمى بشكل صحيح ضمن fixtures
وفقًا للمضيف الذي تم استخدامه.
ستعرف ما إذا كان هناك شيء غير صحيح لأن هذا سيحدث خطأ عند تشغيل 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 © مطاطا
شكرا لجميع المساهمين!