Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Elastic App Search Official PHP Client

License

NotificationsYou must be signed in to change notification settings

elastic/app-search-php

Repository files navigation

⚠️ This client is deprecated⚠️

As of Enterprise Search version 7.13.0, we are directing users to the newEnterprise Search PHP Client anddeprecating this client.

This client will be compatible with all Enterprise Search 7.x releases, but will not be compatible with 8.x releases. Our development effort on this project willbe limited to bug fixes. All future enhancements will be focused on the Enterprise Search PHP Client.

Thank you! - Elastic

Elastic App Search Logo

CircleCI buidl

A first-party PHP client for building excellent, relevant search experiences withElastic App Search.

Contents


Getting started 🐣

Using this client assumes that you have already an instance of Elastic App Search up and running.

You can find more information about Elastic App Search at :https://www.elastic.co/app-search.

You can install the client in your project by using composer:

composer require elastic/app-search

Versioning

This client is versioned and released alongside App Search.

To guarantee compatibility, use the most recent version of this library within the major version of the corresponding App Search implementation.

For example, for App Search7.3, use7.3 of this library or above, but not8.0.

If you are using theSaaS version available on swiftype.com of App Search, you should use the version 7.5.x of the client.

Usage

Configuring the client

Basic client instantiation

To instantiate a new client you can use\Elastic\AppSearch\Client\ClientBuilder:

$apiEndpoint   ='http://localhost:3002/';$apiKey        ='private-XXXXXXXXXXXX';$clientBuilder = \Elastic\AppSearch\Client\ClientBuilder::create($apiEndpoint,$apiKey);$client =$clientBuilder->build();

Notes:

  • The resulting client will be of type\Elastic\AppSearch\Client\Client

  • You can find the API endpoint and your API key URL in the credentials sections of the App Search dashboard.

  • You can use any type of API Key (private, public or admin). The client will throw an exception if you try to execute an action that is not authorized for the key used.

Basic usage

Retrieve or create an engine

Most methods of the API require that you have access to an Engine.

To check if an Engine exists and retrieve its configuration, you can use theClient::getEngine method :

$engine =$client->getEngine('my-engine');

If the Engine does not exists yet, you can create it by using theClient::createEngine method :

$engine =$client->createEngine('my-engine','en');

The second parameter ($language) is optional. Set it tonull to apply theuniversal language.

Read more about language support.

Index some documents

You can use theClient::indexDocuments method to index some documents into the Engine:

$documents = [      ['id' =>'first-document','name' =>'Document name','description' =>'Document description'],      ['id' =>'other-document','name' =>'Other document name','description' =>'Other description'],    ];$indexingResults =$client->indexDocuments('my-engine',$documents);

The$indexingResults array will contain the result of the indexation of each documents. You should always check the content of the result.

Read more about document indexing.

Search

You can use theClient::search method to search in your Engine:

$searchParams = ['page'  => ['current' =>1,'size' =>10]    ];$searchResponse =$client->search('my-engine','search text',$searchParams);

If you want to match all documents you can use and empty search query'' as second parameter ($queryText).

The$searchRequestParams parameter is optional and can be used to use advanced search features. Allowed params are :

Param nameDocumentation URL
pagehttps://swiftype.com/documentation/app-search/api/search#paging
filtershttps://swiftype.com/documentation/app-search/api/search/filters
facetshttps://swiftype.com/documentation/app-search/api/search/facets
sorthttps://swiftype.com/documentation/app-search/api/search/sorting
boostshttps://swiftype.com/documentation/app-search/api/search/boosts
search_fieldshttps://swiftype.com/documentation/app-search/api/search/search-fields
result_fieldshttps://swiftype.com/documentation/app-search/api/search/result-fields
grouphttps://swiftype.com/documentation/app-search/api/search/grouping

The search response will contains at least a meta field and a results field as shown in this example:

['meta' => ['warnings' => [],'page' => ['current' =>1,'total_pages' =>1,'total_results' =>1,'size' =>10      ],'request_id' =>'feff7cf2359a6f6da84586969ef0ca89'    ],'results' => [      ['id' => ['raw' =>'first-document'],'name' => ['raw' =>'Document name'],'description' => ['raw' => ['Document description']      ]    ]  ]]

Clients methods

MethodDescriptionDocumentation
createEngineCreates a new engine.

Parameters :
-$name (required)
-$language
Endpoint Documentation
createMetaEngineCreates a new meta engine.

Parameters :
-$name (required)
-$sourceEngines (required)
Endpoint Documentation
addMetaEngineSourceAdd a source engine to an existing meta engine.

Parameters :
-$engineName (required)
-$sourceEngines (required)
Endpoint Documentation
createCurationCreate a new curation.

Parameters :
-$engineName (required)
-$queries (required)
-$promotedDocIds
-$hiddenDocIds
Endpoint Documentation
createSynonymSetCreate a new synonym set.

Parameters :
-$engineName (required)
-$synonyms (required)
Endpoint Documentation
deleteCurationDelete a curation by id.

Parameters :
-$engineName (required)
-$curationId (required)
Endpoint Documentation
deleteDocumentsDelete documents by id.

Parameters :
-$engineName (required)
-$documentIds (required)
Endpoint Documentation
deleteEngineDelete an engine by name.

Parameters :
-$engineName (required)
Endpoint Documentation
deleteMetaEngineSourceDelete a source engine from a meta engine.

Parameters :
-$engineName (required)
-$sourceEngines (required)
Endpoint Documentation
deleteSynonymSetDelete a synonym set by id.

Parameters :
-$engineName (required)
-$synonymSetId (required)
Endpoint Documentation
getApiLogsThe API Log displays API request and response data at the Engine level.

Parameters :
-$engineName (required)
-$fromDate (required)
-$toDate (required)
-$currentPage
-$pageSize
-$query
-$httpStatusFilter
-$httpMethodFilter
-$sortDirection
Endpoint Documentation
getCountAnalyticsReturns the number of clicks and total number of queries over a period.

Parameters :
-$engineName (required)
-$filters
-$interval
Endpoint Documentation
getCurationRetrieve a curation by id.

Parameters :
-$engineName (required)
-$curationId (required)
Endpoint Documentation
getDocumentsRetrieves one or more documents by id.

Parameters :
-$engineName (required)
-$documentIds (required)
Endpoint Documentation
getEngineRetrieves an engine by name.

Parameters :
-$engineName (required)
Endpoint Documentation
getSchemaRetrieve current schema for then engine.

Parameters :
-$engineName (required)
Endpoint Documentation
getSearchSettingsRetrive current search settings for the engine.

Parameters :
-$engineName (required)
Endpoint Documentation
getSynonymSetRetrieve a synonym set by id.

Parameters :
-$engineName (required)
-$synonymSetId (required)
Endpoint Documentation
getTopClicksAnalyticsReturns the number of clicks received by a document in descending order.

Parameters :
-$engineName (required)
-$query
-$pageSize
-$filters
Endpoint Documentation
getTopQueriesAnalyticsReturns queries anlaytics by usage count.

Parameters :
-$engineName (required)
-$pageSize
-$filters
Endpoint Documentation
indexDocumentsCreate or update documents.

Parameters :
-$engineName (required)
-$documents (required)
Endpoint Documentation
listCurationsRetrieve available curations for the engine.

Parameters :
-$engineName (required)
-$currentPage
-$pageSize
Endpoint Documentation
listDocumentsList all available documents with optional pagination support.

Parameters :
-$engineName (required)
-$currentPage
-$pageSize
Endpoint Documentation
listEnginesRetrieves all engines with optional pagination support.

Parameters :
-$currentPage
-$pageSize
Endpoint Documentation
listSynonymSetsRetrieve available synonym sets for the engine.

Parameters :
-$engineName (required)
-$currentPage
-$pageSize
Endpoint Documentation
logClickthroughSend data about clicked results.

Parameters :
-$engineName (required)
-$queryText (required)
-$documentId (required)
-$requestId
-$tags
Endpoint Documentation
multiSearchRun several search in the same request.

Parameters :
-$engineName (required)
-$queries (required)
Endpoint Documentation
querySuggestionProvide relevant query suggestions for incomplete queries.

Parameters :
-$engineName (required)
-$query (required)
-$fields
-$size
Endpoint Documentation
resetSearchSettingsReset search settings for the engine.

Parameters :
-$engineName (required)
Endpoint Documentation
searchAllows you to search over, facet and filter your data.

Parameters :
-$engineName (required)
-$queryText (required)
-$searchRequestParams
Endpoint Documentation
updateCurationUpdate an existing curation.

Parameters :
-$engineName (required)
-$curationId (required)
-$queries (required)
-$promotedDocIds
-$hiddenDocIds
Endpoint Documentation
updateDocumentsPartial update of documents.

Parameters :
-$engineName (required)
-$documents (required)
Endpoint Documentation
updateSchemaUpdate schema for the current engine.

Parameters :
-$engineName (required)
-$schema (required)
Endpoint Documentation
updateSearchSettingsUpdate search settings for the engine.

Parameters :
-$engineName (required)
-$searchSettings (required)
Endpoint Documentation

Development

Code for the endpoints is generated automatically using a custom version ofOpenAPI Generator.

To regenerate endpoints, use the docker laucher packaged invendor/bin:

./vendor/bin/elastic-openapi-codegen.sh

The custom generator will be built and launched using the following Open API spec file :resources/api/api-spec.yml.

You can then commit and PR the modified api-spec file and your endpoints code files.

The client class and readme may be changed in some cases. Do not forget to include them in your commit!

FAQ 🔮

Where do I report issues with the client?

If something is not working as expected, please open anissue.

Where can I find the full API documentation ?

Your best bet is to read thedocumentation.

Where else can I go to get help?

You can checkout theElastic community discuss forums.

Contribute 🚀

We welcome contributors to the project. Before you begin, a couple notes...

License 📗

Apache 2.0 ©Elastic

Thank you to all thecontributors!


[8]ページ先頭

©2009-2025 Movatter.jp