Comments (10)
For now, the only way to access Search API is to make requests directly. See docs for more info about the endpoint.
We plan to add it to the client soon though. We've been focusing our efforts on releasing new Ruby and Python clients, and Node client is the next one on our roadmap.
from workplace-search-node.
I'll close this but please let me know if you have any more questions.
from workplace-search-node.
I just tried making the request directly using curl and got this response:
<!-- This is a random-length HTML comment: ijlhfusokxoocvljfpktqjxmlnmkqxrpmbpecrvbvsdtwitphaoshwltwacbutxgfmkwfvjfbdpeboqtdgxxbwaekyktefnfaxgyzwyoaikqhtxvpzvhwusmbajrmhzmnwpsnxebcrkevcdzcgmslaxijhntlliywercogpznzumuvzshioejvynkuuyfyodvmuarzbwhzedmzfkaetjiucukrdapbqqgbmonfzllfpauqzdqyleegbbwacdrgjnjzkgvgdzwltpejrzjprpjpznyqahwrtkqx -->
I tried the same using Postman and got a similar message with the status code 403 (Forbidden)
Am I missing something ?
from workplace-search-node.
Have you provided access_token
authorization header? It is required for making requests.
from workplace-search-node.
yes I provided an access_token. I used the access token in the credentials of my custom source like this:
https://ibb.co/DgxL6yJ
curl -X POST https://......ent-search.eu-central-1.aws.cloud.es.io/api/ws/v1/search \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"query": "..."
}'
from workplace-search-node.
I'm not very familiar with Oauth flow, but based on the documentation it looks like you need to set up an Oauth application in Workplace Search and get access token through Oauth flow:
from workplace-search-node.
The access token from the Custom Source page cannot be used with the Search API.
This access token can be used for document ingestion for custom sources, but it does not have permissions to access the Search API.
An access token that can be used with the Search API can be retrieved for authenticated users with OAuth.
We have documentation on how to set the OAuth app in Workplace Search and what APIs to call for the OAuth flow:
https://www.elastic.co/guide/en/workplace-search/7.10/building-custom-search-workplace-search.html#configuring-search-oauth
https://www.elastic.co/guide/en/workplace-search/7.10/workplace-search-search-oauth.html
Hope this helps!
from workplace-search-node.
Thank you. I just tried this and it worked as expected. But I noticed that the token is only valid for a short period of time (2h).
Is it possible to get a token that doesn't expire?
My goal is to issue search requests from a nodejs backend application without user interaction! This is needed because I want to sync a custom source so I need to check if a document is already indexed or has changed before indexing.
from workplace-search-node.
When obtaining an access_token
, a refresh_token
is also returned.
curl -X POST 'http://localhost:3002/ws/oauth/token?grant_type=authorization_code&client_id=ca6e5332b...&client_secret=c5d51a8c...&redirect_uri=https://one.acme.co&code=78hasd9h324h...'
{
"access_token": "79e765efe18f5f5f2dbcb8404097d52c64ceb84a3cb0a51205157b4141cdd77d",
"token_type": "Bearer",
"expires_in": 7200,
"refresh_token": "fe010bbca37279ae6b4c0f117cf15a37d992adb50a6d83c930ab827ec4081e07",
"scope": "search"
}
The refresh_token
can be used to obtain a new access_token
:
curl -X POST "http://localhost:3002/ws/oauth/token?grant_type=refresh_token&client_id=ca6e5332b...&client_secret=c5d51a8c...&refresh_token=fe010b..."
{
"access_token":"b84...",
"token_type":"Bearer",
"expires_in":7200,
"refresh_token":"eb6...",
"scope":"search"
}
This request returns a fresh access_token
and also another refresh_token
.
One important note is that the old refresh_token
cannot be re-used.
So every time we refresh the access_token
we also have to store the new refresh_token
for future usage.
from workplace-search-node.
so that means the refresh_token doesn't expire until it is used.
Thanks again for the detailed answer, this was very helpful.
from workplace-search-node.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from workplace-search-node.