ลูกค้ารายนี้เลิกใช้แล้ว ตั้งแต่ Enterprise Search เวอร์ชัน 7.10.0 เป็นต้นไป เรากำลังนำผู้ใช้ไปยัง Enterprise Search Python Client ใหม่ และเลิกใช้งานไคลเอ็นต์นี้
ไคลเอนต์นี้จะเข้ากันได้กับรุ่น Enterprise Search 7.x ทั้งหมด แต่จะเข้ากันไม่ได้กับรุ่น 8.x ความพยายามในการพัฒนาโครงการนี้ของเราจะถูกจำกัดอยู่เพียงการแก้ไขข้อบกพร่องเท่านั้น การปรับปรุงในอนาคตทั้งหมดจะมุ่งเน้นไปที่ Enterprise Search Python Client
ขอบคุณ! - ยางยืด
ไคลเอนต์ Python บุคคลที่หนึ่งสำหรับการสร้างประสบการณ์การค้นหาที่ยอดเยี่ยมและเกี่ยวข้องด้วย Elastic App Search
หากต้องการติดตั้งไคลเอนต์ ให้ใช้ pip:
python - m pip install elastic - app - search
คุณยังสามารถดาวน์โหลดซอร์สโปรเจ็กต์และรัน::
python setup . py install
ลูกค้ารายนี้ได้รับเวอร์ชันและเผยแพร่ควบคู่ไปกับ App Search
เพื่อรับประกันความเข้ากันได้ ให้ใช้เวอร์ชันล่าสุดของไลบรารีนี้ภายในเวอร์ชันหลักของการใช้งาน App Search ที่เกี่ยวข้อง
ตัวอย่างเช่น สำหรับ App Search 7.3
ให้ใช้ 7.3
ของไลบรารีนี้หรือสูงกว่า แต่ไม่ใช่ 8.0
หากคุณใช้เวอร์ชัน SaaS ที่มีอยู่ใน Swiftype.com ของ App Search คุณควรใช้เวอร์ชัน 7.5.x ของไคลเอ็นต์
การใช้ไคลเอนต์นี้จะถือว่าคุณมีอินสแตนซ์ของ Elastic App Search ที่ใช้งานอยู่แล้ว
ไคลเอ็นต์สามารถสร้างอินสแตนซ์ได้โดยใช้พารามิเตอร์ base_endpoint
, api_key
และ use_https
:
>> > from elastic_app_search import Client
>> > client = Client (
base_endpoint = 'localhost:3002/api/as/v1' ,
api_key = 'private-mu75psc5egt9ppzuycnc2mc3' ,
use_https = False
)
หมายเหตุ:
[api_key]
ตรวจสอบสิทธิ์คำขอไปยัง API คุณสามารถใช้คีย์ประเภทใดก็ได้กับไคลเอ็นต์ แต่คีย์แต่ละประเภทมีขอบเขตที่แตกต่างกัน สำหรับข้อมูลเพิ่มเติมเกี่ยวกับคีย์ โปรดดูเอกสารประกอบ
base_endpoint
ต้องยกเว้นโปรโตคอลและรวมคำนำหน้า api/as/v1
โดยทั่วไปจะพบได้ในแท็บข้อมูลรับรองภายในแดชบอร์ดการค้นหาแอป
ตั้งค่า use_https
เป็น True
หรือ False
ขึ้นอยู่กับการกำหนดค่าเซิร์ฟเวอร์ของคุณ บ่อยครั้งจะเป็น False
เมื่อทำงานในการพัฒนาบน localhost
และ True
สำหรับสภาพแวดล้อมการใช้งานจริง
ต่อไปนี้คือตัวอย่างการกำหนดค่าสำหรับ Elastic Cloud:
>> > from elastic_app_search import Client
>> > client = Client (
base_endpoint = '77bf13bc2e9948729af339a446b06ddcc.app-search.us-east-1.aws.found.io/api/as/v1' ,
api_key = 'private-mu75psc5egt9ppzuycnc2mc3' ,
use_https = True
)
เมื่อใช้เวอร์ชัน SaaS ที่มีอยู่ใน Swiftype.com ของ App Search คุณสามารถกำหนดค่าไคลเอ็นต์โดยใช้ host_identifier
แทนพารามิเตอร์ base_endpoint
สามารถพบได้ในเมนู host_identifier
รับรอง
>> > from elastic_app_search import Client
>> > host_identifier = 'host-c5s2mj'
>> > api_key = 'private-mu75psc5egt9ppzuycnc2mc3'
>> > client = Client ( host_identifier , api_key )
>> > engine_name = 'favorite-videos'
>> > document = {
'id' : 'INscMGmhmX4' ,
'url' : 'https://www.youtube.com/watch?v=INscMGmhmX4' ,
'title' : 'The Original Grumpy Cat' ,
'body' : 'A wonderful video of a magnificent cat.'
}
>> > client . index_document ( engine_name , document )
{ 'id' : 'INscMGmhmX4' }
>> > engine_name = 'favorite-videos'
>> > 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 . index_documents ( engine_name , documents )
[{ 'id' : 'INscMGmhmX4' , 'errors' : []}, { 'id' : 'JNDFojsd02' , 'errors' : []}]
>> > engine_name = 'favorite-videos'
>> > documents = [
{
'id' : 'INscMGmhmX4' ,
'title' : 'Updated title'
}
]
>> > client . update_documents ( engine_name , documents )
>> > engine_name = 'favorite-videos'
>> > client . get_documents ( engine_name , [ 'INscMGmhmX4' ])
[{ 'id' : 'INscMGmhmX4' , 'url' : 'https://www.youtube.com/watch?v=INscMGmhmX4' , 'title' : 'The Original Grumpy Cat' , 'body' : 'A wonderful video of a magnificent cat.' }]
>> > engine_name = 'favorite-videos'
>> > client . list_documents ( engine_name , current = 1 , size = 20 )
{
'meta' : {
'page' : {
'current' : 1 ,
'total_pages' : 1 ,
'total_results' : 2 ,
'size' : 20
}
},
'results' : [{ 'id' : 'INscMGmhmX4' , 'url' : 'https://www.youtube.com/watch?v=INscMGmhmX4' , 'title' : 'The Original Grumpy Cat' , 'body' : 'A wonderful video of a magnificent cat.' }]
}
>> > engine_name = 'favorite-videos'
>> > client . destroy_documents ( engine_name , [ 'INscMGmhmX4' ])
[{ 'id' : 'INscMGmhmX4' , 'result' : True }]
>> > engine_name = 'favorite-videos'
>> > client . get_schema ( engine_name )
{ 'name' : 'text' , 'square_km' : 'number' , 'square_mi' : 'text' }
>> > engine_name = 'favorite-videos'
>> > client . update_schema ( engine_name , { 'square_km' : 'text' })
{ 'square_km' : 'text' }
>> > client . update_schema ( engine_name , { 'square_mi' : 'text' })
{ 'square_km' : 'text' , 'square_mi' : 'text' }
>> > client . update_schema ( engine_name , { 'square_km' : 'number' })
{ 'square_km' : 'number' , 'square_mi' : 'text' }
>> > client . list_engines ( current = 1 , size = 20 )
{
'meta' : {
'page' : {
'current' : 1 ,
'total_pages' : 1 ,
'total_results' : 2 ,
'size' : 20
}
},
'results' : [{ 'name' : 'favorite-videos' }, { 'name' : 'another-engine' }]
}
>> > client . get_engine ( 'favorite-videos' )
{ 'name' : 'favorite-videos' }
>> > client . create_engine ( 'favorite-videos' , 'en' )
{ 'name' : 'favorite-videos' , 'type' : 'default' , 'language' : 'en' }
>> > client . destroy_engine ( 'favorite-videos' )
{ 'deleted' : True }
>> > client . list_synonym_sets ( 'us-national-parks' )
{
'meta' : {
'page' : {
'current' : 1 ,
'total_pages' : 1 ,
'total_results' : 3 ,
'size' : 20
}
},
'results' : [
{
'id' : 'syn-5b11ac66c9f9292013220ad3' ,
'synonyms' : [
'park' ,
'trail'
]
},
{
'id' : 'syn-5b11ac72c9f9296b35220ac9' ,
'synonyms' : [
'protected' ,
'heritage'
]
},
{
'id' : 'syn-5b11ac66c9f9292013220ad3' ,
'synonyms' : [
'hectares' ,
'acres'
]
}
]
}
>> > client . list_synonym_sets ( 'us-national-parks' , size = 1 , current = 1 )
{
'meta' : {
'page' : {
'current' : 1 ,
'total_pages' : 3 ,
'total_results' : 3 ,
'size' : 1
}
},
'results' : [
{
'id' : 'syn-5b11ac66c9f9292013220ad3' ,
'synonyms' : [
'park' ,
'trail'
]
}
]
}
>> > client . get_synonym_set ( 'us-national-parks' , 'syn-5b11ac66c9f9292013220ad3' )
{
'id' : 'syn-5b11ac66c9f9292013220ad3' ,
'synonyms' : [
'park' ,
'trail'
]
}
>> > client . create_synonym_set ( 'us-national-parks' , [ 'park' , 'trail' ])
{
'id' : 'syn-5b11ac72c9f9296b35220ac9' ,
'synonyms' : [
'park' ,
'trail'
]
}
>> > client . update_synonym_set ( 'us-national-parks' , 'syn-5b11ac72c9f9296b35220ac9' , [ 'park' , 'trail' , 'ground' ])
{
'id' : 'syn-5b11ac72c9f9296b35220ac9' ,
'synonyms' : [
'park' ,
'trail' ,
'ground'
]
}
>> > client . destroy_synonym_set ( 'us-national-parks' , 'syn-5b11ac66c9f9292013220ad3' )
{
'deleted' : True
}
>> > client . search ( 'favorite-videos' , 'grumpy cat' , {})
{ 'meta' : { 'page' : { 'current' : 1 , 'total_pages' : 1 , 'total_results' : 2 , 'size' : 10 }, ...}, 'results' : [...]}
>> > client . multi_search ( 'favorite-videos' , [{
'query' : 'cat' ,
'options' : { 'search_fields' : { 'title' : {} }}
},{
'query' : 'dog' ,
'options' : { 'search_fields' : { 'body' : {} }}
}])
[{ 'meta' : {...}, 'results' : [...]}, { 'meta' : {...}, 'results' : [...]}]
>> > client . query_suggestion ( 'favorite-videos' , 'cat' , {
'size' : 10 ,
'types' : {
'documents' : {
'fields' : [ 'title' ]
}
}
})
{ 'results' : { 'documents' : [{ 'suggestion' : 'cat' }]}, 'meta' : { 'request_id' : '390be384ad5888353e1b32adcfaaf1c9' }}
>> > client . click ( engine_name , { 'query' : 'cat' , 'document_id' : 'INscMGmhmX4' })
การสร้างคีย์การค้นหาที่จะค้นหาเฉพาะฟิลด์เนื้อหาเท่านั้น
>> > api_key = 'search-xxxxxxxxxxxxxxxxxxxxxxxx'
>> > api_key_name = 'search-key' # This name must match the name of the key above from your App Search dashboard
>> > signed_search_key = Client . create_signed_search_key ( api_key , api_key_name , { 'search_fields' : { 'body' : {}}})
>> > client = Client (
base_endpoint = 'localhost:3002/api/as/v1' ,
api_key = signed_search_key ,
use_https = False
)
>> > client . create_meta_engine (
engine_name = engine_name ,
source_engines = [
'source-engine-1' ,
'source-engine-2'
]
)
{ 'source_engines' : [ 'source-engine-1' , 'source-engine-2' ], 'type' : 'meta' , 'name' : 'my-meta-engine' }
>> > client . add_meta_engine_sources ( 'my-meta-engine' , [ 'source-engine-3' ])
{ 'source_engines' : [ 'source-engine-1' , 'source-engine-2' , 'source-engine-3' ], 'type' : 'meta' , 'name' : 'my-meta-engine' }
>> > client . delete_meta_engine_sources ( 'my-meta-engine' , [ 'source-engine-3' ])
{ 'source_engines' : [ 'source-engine-1' , 'source-engine-2' ], 'type' : 'meta' , 'name' : 'my-meta-engine' }
>> > client . get_api_logs ( 'my-meta-engine' , {
"filters" : {
"date" : {
"from" : "2020-03-30T00:00:00+00:00" ,
"to" : "2020-03-31T00:00:00+00:00"
},
"status" : "429"
}
})
{
'results' : [],
'meta' : {
'query' : '' ,
'filters' : {
'date' : {
'from' : '2020-03-27T00:00:00+00:00' ,
'to' : '2020-03-31T00:00:00+00:00'
},
'status' : '429'
},
'sort_direction' : 'asc' ,
'page' : {
'current' : 1 ,
'total_pages' : 0 ,
'total_results' : 0 ,
'size' : 10
}
}
}
>> > client . get_search_settings ( engine_name = 'us-national-parks' )
{
"search_fields" : {
"name" : {
"weight" : 1
},
"description" : {
"weight" : 1
}
},
"result_fields" : {
"name" : {
"raw" : {}
},
"description" : {
"raw" : {}
}
},
"boosts" : {}
}
>> > client . update_search_settings (
engine_name = 'us-national-parks' ,
search_settings = {
"search_fields" : {
"name" : {
"weight" : 2
},
"description" : {
"weight" : 1
}
},
"result_fields" : {
"name" : {
"raw" : {}
},
"description" : {
"raw" : {}
}
},
"boosts" : {}
}
)
{
"search_fields" : {
"name" : {
"weight" : 2
},
"description" : {
"weight" : 1
}
},
"result_fields" : {
"name" : {
"raw" : {}
},
"description" : {
"raw" : {}
}
},
"boosts" : {}
}
>> > client . reset_search_settings ( engine_name = 'us-national-parks' )
{
"search_fields" : {
"name" : {
"weight" : 1
},
"description" : {
"weight" : 1
}
},
"boosts" : {}
}
python setup . py test
หากมีบางอย่างไม่ทำงานตามที่คาดไว้ โปรดเปิดปัญหา
ทางออกที่ดีที่สุดของคุณคือการอ่านเอกสาร
คุณสามารถตรวจสอบฟอรัมสนทนาของชุมชน Elastic App Search ได้
เรายินดีต้อนรับผู้ร่วมโครงการ ก่อนที่คุณจะเริ่ม โปรดทราบว่า:
Apache 2.0 © ยืดหยุ่น
ขอขอบคุณผู้มีส่วนร่วมทุกคน!