Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 4.2.x] Documentation / Elasticsearch query endpoint - query samples #7732

Merged
merged 5 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
161 changes: 157 additions & 4 deletions docs/manual/docs/api/search.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,162 @@
# Search Service

## Elasticsearch

GeoNetwork provides a full Elasticsearch end-point: ``/srv/api/search/records/_search``
GeoNetwork provides a access to ***Elasticsearch*** `/srv/api/search/records/_search` and `/srv/api/search/records/_msearch` end-points. These endpoints accept `POST` requests, with request body containing an Elasticsearch JSON query.

Reference

- [Search API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html) (Elasticsearch)
- [Search API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html) ( Elasticsearch Guide )
- [Multi search API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html) (Elasticsearch Guide)

## Search API examples

This section provides some query `POST` examples of `/srv/api/search/records/_search` end-point:

1. To test examples navigate Swagger API documentation at `/srv/api/index.html`

2. Locate the *search* heading, and the `/search/records/_search` `POST` end-point

3. Use the *Try it out* button with:

* **bucket**: `metadata`
* **relatedType**:
* **Request body**: Chosen from the examples below

4. Press **Execute** to run the example.

![](img/swagger-search-endpoint.png)

### Text search query

Query with any field for metadata containing the string `infrastructure`, using a query with Lucene syntax and excluding metadata templates:

```json
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "+anytext:infrastructure "
}
}
],
"filter": [
{
"term": {
"isTemplate": {
"value": "n"
}
}
}
]
}
}
}
```

### Subset results

Query with any field for metadata containing the string `infrastructure`, using a query with Lucene syntax and excluding metadata templates, returning a subset of the information:

```json
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "+anytext:infrastructure "
}
}
],
"filter": [
{
"term": {
"isTemplate": {
"value": "n"
}
}
}
]
}
},
"_source": {
"includes": [
"uuid",
"id",
"resourceType",
"resourceTitle*",
"resourceAbstract*"
]
}
}
```

### Dataset query

Query datasets with title containing the string `infrastructure`, using a query with Lucene syntax and excluding metadata templates:

```json
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "+anytext:infrastructure +resourceType:dataset"
}
}
],
"filter": [
{
"term": {
"isTemplate": {
"value": "n"
}
}
}
]
}
}
}
```

### Revision date query

Query datasets with a revision date in June 2019 and excluding metadata templates:

```json
{
"query": {
"bool": {
"must": [
{
"term": {
"resourceType": {
"value": "dataset"
}
}
},
{
"range": {
"resourceTemporalDateRange": {
"gte": "2019-06-01",
"lte": "2019-06-30",
"relation": "intersects"
}
}
}
],
"filter": [
{
"term": {
"isTemplate": {
"value": "n"
}
}
}
]
}
}
}
```