elasticsearch/docs/reference/query-languages/query-dsl/query-dsl-pinned-query.md
Craig Taverner 94cad286bc
Restructure query-languages docs files for clarity (#124797)
In a few previous PR's we restructured the ES|QL docs to make it possible to generate them dynamically.

This PR just moves a few files around to make the query languages docs easier to work with, and a little more organized like the ES|QL docs.

A bit part of this was setting up redirects to the new locations, so other repo's could correctly link to the elasticsearch docs.
2025-03-17 17:58:58 +01:00

80 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
mapped_pages:
- https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-pinned-query.html
---
# Pinned query [query-dsl-pinned-query]
Promotes selected documents to rank higher than those matching a given query. This feature is typically used to guide searchers to curated documents that are promoted over and above any "organic" matches for a search. The promoted or "pinned" documents are identified using the document IDs stored in the [`_id`](/reference/elasticsearch/mapping-reference/mapping-id-field.md) field.
## Example request [_example_request]
```console
GET /_search
{
"query": {
"pinned": {
"ids": [ "1", "4", "100" ],
"organic": {
"match": {
"description": "iphone"
}
}
}
}
}
```
## Top-level parameters for `pinned` [pinned-query-top-level-parameters]
`ids`
: (Optional, array) [Document IDs](/reference/elasticsearch/mapping-reference/mapping-id-field.md) listed in the order they are to appear in results. Required if `docs` is not specified.
`docs`
: (Optional, array) Documents listed in the order they are to appear in results. Required if `ids` is not specified. You can specify the following attributes for each document:
`_id`
: (Required, string) The unique [document ID](/reference/elasticsearch/mapping-reference/mapping-id-field.md).
`_index`
: (Optional, string) The index that contains the document.
`organic`
: Any choice of query used to rank documents which will be ranked below the "pinned" documents.
## Pin documents in a specific index [_pin_documents_in_a_specific_index]
If youre searching over multiple indices, you can pin a document within a specific index using `docs`:
```console
GET /_search
{
"query": {
"pinned": {
"docs": [
{
"_index": "my-index-000001", <1>
"_id": "1"
},
{
"_id": "4" <2>
}
],
"organic": {
"match": {
"description": "iphone"
}
}
}
}
}
```
1. The document with id `1` from `my-index-000001` will be the first result.
2. When `_index` is missing, all documents with id `4` from the queried indices will be pinned with the same score.