Skip to content

Commit a76ca89

Browse files
committed
deprecate old search endpoint
1 parent 49ce3d2 commit a76ca89

File tree

6 files changed

+82
-31
lines changed

6 files changed

+82
-31
lines changed

docs/api-reference/v2/endpoints/search/get-search.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ title: "Search"
33
openapi: firework-v2-openapi get /search/
44
---
55

6+
<Warning>
7+
**DEPRECATED:** This endpoint should be replaced by
8+
[/firework/v4/events/global/_search <Icon icon="code" size={16} />](/api-reference/v4/endpoints/global-search)
9+
</Warning>
10+
611
import GlobalSearchApiQuotaNote from '/snippets/global-search-api-quota-note.mdx';
712

8-
<GlobalSearchApiQuotaNote />
13+
<GlobalSearchApiQuotaNote />

docs/api-reference/v2/endpoints/search/post-search.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ openapi: firework-v2-openapi post /search/
33
title: Search
44
---
55

6+
<Warning>
7+
**DEPRECATED:** This endpoint should be replaced by
8+
[/firework/v4/events/global/_search <Icon icon="code" size={16} />](/api-reference/v4/endpoints/global-search)
9+
</Warning>
10+
611
import GlobalSearchApiQuotaNote from '/snippets/global-search-api-quota-note.mdx';
712

8-
<GlobalSearchApiQuotaNote />
13+
<GlobalSearchApiQuotaNote />

docs/api-reference/v4/endpoints/global-search.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Search (new)"
2+
title: "Search"
33
api: "POST https://api.flare.io/firework/v4/events/global/_search"
44
---
55

docs/guides/global-search.mdx

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Search in All of Flare's Events"
33
---
44

55
Global searches in Flare is exposed through the
6-
[/search <Icon icon="code" size={16} />](/api-reference/v2/endpoints/search/get-search)
6+
[global/_search <Icon icon="code" size={16} />](/api-reference/v4/endpoints/global-search)
77
endpoint.
88

99
This guide details a typical search use case and provides an example for how to impement it.
@@ -20,12 +20,10 @@ To achieve the desired results, the following parameters will be used:
2020

2121
| Parameter | Value | Justification |
2222
| --------- | ----- | ------------- |
23-
| query | fraud | The keyword we are looking for. |
24-
| lite | true | Quickly browse results, but don't ask for the full content. |
25-
| types[] | chat_message | Retrieve only the chat_message events. |
23+
| query.query_string | hello | The keyword we are looking for. |
24+
| filter.types | chat_message | Retrieve only the chat_message events. |
2625
| order | asc | Retrieve results in ascending order so that we can resume fetching in the future. |
27-
| times | `<from_date>@` | Replace `<from_date>` with a timestamp that corresponds to 6 hours ago and don't set anything after the `@` so that we can fetch all results until the current time. |
28-
| sort_by | searchable | Sort results in the order that they have been added to Flare's database. |
26+
| filter.estimated_created_at.gte | `<from_date>` | Replace `<from_date>` with a timestamp that corresponds to 6 hours that we can fetch all results until the current time.
2927

3028

3129
## Paging
@@ -50,6 +48,7 @@ These are end-to-end examples in various programming languages.
5048
import datetime
5149
import os
5250
import time
51+
import urllib.parse
5352

5453
from flareio import FlareApiClient
5554

@@ -68,26 +67,48 @@ last_from: str | None = None
6867
fetched_pages: int = 0
6968

7069
for resp in api_client.scroll(
71-
method="GET",
72-
url="/firework/v2/search/",
73-
params={
74-
"query": "fraud",
75-
"lite": "true",
70+
method="POST",
71+
url="/firework/v4/events/global/_search",
72+
json={
73+
"size": 10,
7674
"order": "asc",
77-
"sort_by": "searchable",
78-
"types[]": "chat_message",
79-
"time": f"{from_timestamp}@",
8075
"from": None,
76+
"filters": {
77+
"type": ["chat_message"],
78+
"estimated_created_at": {"gte": from_timestamp},
79+
},
80+
"query": {
81+
"type": "query_string",
82+
"query_string": "hello",
83+
},
8184
},
8285
):
8386
# Rate limiting.
8487
time.sleep(1)
8588

8689
resp_data: dict = resp.json()
90+
items: list[dict] = resp_data["items"]
8791

8892
fetched_pages += 1
89-
num_results: int = len(resp_data["items"])
90-
print(f"Fetched page {fetched_pages} with {num_results} results...")
93+
print(f"Fetched page {fetched_pages} with {len(items)} results...")
94+
95+
# (Optional): Get the full data
96+
for item in items:
97+
# Rate limiting.
98+
time.sleep(1)
99+
100+
# This will contain 3 parts: 'index', 'source', and 'id'
101+
parsed_uid: list[str] = item["metadata"]["uid"].split("/", maxsplit=2)
102+
103+
event_response = api_client.get(
104+
"/firework/v2/activities/"
105+
+ "/".join(
106+
urllib.parse.quote_plus(uid_component) for uid_component in parsed_uid
107+
)
108+
)
109+
110+
full_data = event_response.json()
111+
print(f"Here is the full data of the event: {full_data}")
91112

92113
# Save the last "next" value.
93114
last_from = resp_data.get("next") or last_from

docs/guides/tenant-events.mdx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ These are end-to-end examples in various programming languages.
9797

9898
<Accordion title="Python SDK Example">
9999
```python
100+
import datetime
100101
import os
101102
import time
102103
import urllib.parse
@@ -110,44 +111,58 @@ if not api_key:
110111

111112
api_client = FlareApiClient(api_key=api_key)
112113

114+
from_timestamp: str = (
115+
datetime.datetime.now(tz=datetime.timezone.utc) - datetime.timedelta(hours=1)
116+
).isoformat()
117+
113118
last_from: str | None = None
114119
fetched_pages: int = 0
115120

116121
for resp in api_client.scroll(
117122
method="POST",
118-
url="/firework/v4/events/tenant/_search",
123+
url="/firework/v4/events/global/_search",
119124
json={
120-
"from": last_from,
125+
"size": 10,
126+
"order": "asc",
127+
"from": None,
128+
"filters": {
129+
"type": ["chat_message"],
130+
"estimated_created_at": {"gte": from_timestamp},
131+
},
132+
"query": {
133+
"type": "query_string",
134+
"query_string": "hello",
135+
},
121136
},
122137
):
123138
# Rate limiting.
124139
time.sleep(1)
125140

126141
resp_data: dict = resp.json()
142+
items: list[dict] = resp_data["items"]
127143

128144
fetched_pages += 1
129-
num_results: int = len(resp_data["items"])
130-
print(f"Fetched page {fetched_pages} with {num_results} results...")
145+
print(f"Fetched page {fetched_pages} with {len(items)} results...")
131146

132147
# Save the last "next" value.
133148
last_from = resp_data.get("next") or last_from
134149

135-
# Get the full data
136-
for item in resp_data["items"]:
150+
# (Optional): Get the full data
151+
for item in items:
137152
# Rate limiting.
138153
time.sleep(1)
139154

140155
# This will contain 3 parts: 'index', 'source', and 'id'
141156
parsed_uid: list[str] = item["metadata"]["uid"].split("/", maxsplit=2)
142157

143-
response = api_client.get(
158+
event_response = api_client.get(
144159
"/firework/v2/activities/"
145160
+ "/".join(
146161
urllib.parse.quote_plus(uid_component) for uid_component in parsed_uid
147162
)
148163
)
149164

150-
full_data = response.json()
165+
full_data = event_response.json()
151166
print(f"Here is the full data of the event: {full_data}")
152167
```
153168
</Accordion>

docs/mint.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,8 @@
185185
{
186186
"group": "Global Search",
187187
"pages": [
188-
"api-reference/v4/endpoints/global-search",
189-
"api-reference/v2/endpoints/search/get-search",
190-
"api-reference/v2/endpoints/search/post-search"
191-
]
188+
"api-reference/v4/endpoints/global-search"
189+
]
192190
}
193191
]
194192
},
@@ -279,6 +277,13 @@
279277
{
280278
"group": "Deprecated APIs",
281279
"pages": [
280+
{
281+
"group": "Global Search",
282+
"pages": [
283+
"api-reference/v2/endpoints/search/get-search",
284+
"api-reference/v2/endpoints/search/post-search"
285+
]
286+
},
282287
{
283288
"group": "Identities",
284289
"pages": [

0 commit comments

Comments
 (0)