-
Notifications
You must be signed in to change notification settings - Fork 888
/
README.md
136 lines (95 loc) · 3.98 KB
/
README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# data
The data plugin provides common data access services, such as `search` and `query`, for solutions and application developers.
## Autocomplete
The autocomplete service provides suggestions for field names and values.
It is wired into the `TopNavMenu` component, but can be used independently.
### Fetch Query Suggestions
The `getQuerySuggestions` function helps to construct a query.
```.ts
// `inputValue` is the user input
const querySuggestions = await autocomplete.getQuerySuggestions({
language: 'kuery',
indexPatterns: [indexPattern],
query: inputValue,
});
```
### Fetch Value Suggestions
The `getValueSuggestions` function returns suggestions for field values.
This is helpful when you want to provide a user with options, for example when constructing a filter.
```.ts
// `inputValue` is the user input
const valueSuggestions = await autocomplete.getValueSuggestions({
indexPattern,
field,
query: inputValue,
});
```
## Field Formats
Coming soon.
## Index Patterns
Coming soon.
## Query
The query service is responsible for managing the configuration of a search query (`QueryState`): filters, time range, query string, and settings such as the auto refresh behavior and saved queries.
It contains sub-services for each of those configurations:
- `data.query.filterManager` - Manages the `filters` component of a `QueryState`. The global filter state (filters that are persisted between applications) are owned by this service.
- `data.query.timefilter` - Responsible for the time range filter and the auto refresh behavior settings.
- `data.query.queryString` - Responsible for the query string and query language settings.
- `data.query.savedQueries` - Responsible for persisting a `QueryState` into a `SavedObject`, so it can be restored and used by other applications.
Any changes to the `QueryState` are published on the `data.query.state$`, which is useful when wanting to persist global state or run a search upon data changes.
A simple use case is:
```.ts
function searchOnChange(indexPattern: IndexPattern, aggConfigs: AggConfigs) {
data.query.state$.subscribe(() => {
// Constuct the query portion of the search request
const query = data.query.getOpenSearchQuery(indexPattern);
// Construct a request
const request = {
params: {
index: indexPattern.title,
body: {
aggs: aggConfigs.toDsl(),
query,
},
},
};
// Search with the `data.query` config
const search$ = data.search.search(request);
...
});
}
```
## Search
Provides access to OpenSearch using the high-level `SearchSource` API or low-level `Search Strategies`.
### SearchSource
The `SearchSource` API is a convenient way to construct and run an OpenSearch search query.
```.tsx
const searchSource = await data.search.searchSource.create();
const searchResponse = await searchSource
.setParent(undefined)
.setField('index', indexPattern)
.setField('filter', filters)
.fetch();
```
### Low-level search
#### Default Search Strategy
One benefit of using the low-level search API is that it allows for a better and more responsive user experience with partial responses.
In OSS only the final result is returned.
```.ts
import { isCompleteResponse } from '../plugins/data/public';
const search$ = data.search.search(request)
.subscribe({
next: (response) => {
if (isCompleteResponse(response)) {
// Final result
search$.unsubscribe();
} else {
// Partial result - you can update the UI, but data is still loading
}
},
error: (e: Error) => {
// Show customized toast notifications.
// You may choose to handle errors differently if you prefer.
data.search.showError(e);
},
});
```