elasticsearch/docs/reference/query-dsl/pinned-query.asciidoc
James Rodewig f56a0f4b66
[DOCS] Remove testenv annotations from doc snippet tests (#80023)
Removes `testenv` annotations and related code. These annotations originally let you skip x-pack snippet tests in the docs. However, that's no longer possible.

Relates to #79309, #31619
2021-11-05 18:38:50 -04:00

82 lines
2 KiB
Text

[role="xpack"]
[[query-dsl-pinned-query]]
=== 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 <<mapping-id-field,`_id`>> field.
==== Example request
[source,console]
--------------------------------------------------
GET /_search
{
"query": {
"pinned": {
"ids": [ "1", "4", "100" ],
"organic": {
"match": {
"description": "iphone"
}
}
}
}
}
--------------------------------------------------
[[pinned-query-top-level-parameters]]
==== Top-level parameters for `pinned`
`ids`::
(Optional, array) <<mapping-id-field, Document IDs>> 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 <<mapping-id-field, document ID>>.
`_index`::
(Required, 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
If you're searching over multiple indices, you can pin a document within a specific index using `docs`:
[source,console]
--------------------------------------------------
GET /_search
{
"query": {
"pinned": {
"docs": [
{
"_index": "my-index-000001",
"_id": "1"
},
{
"_index": "my-index-000001",
"_id": "4"
},
{
"_index": "my-index-000002",
"_id": "100"
}
],
"organic": {
"match": {
"description": "iphone"
}
}
}
}
}
--------------------------------------------------