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 _id field.

Example request

  1. GET /_search
  2. {
  3. "query": {
  4. "pinned": {
  5. "ids": [ "1", "4", "100" ],
  6. "organic": {
  7. "match": {
  8. "description": "iphone"
  9. }
  10. }
  11. }
  12. }
  13. }

Top-level parameters for pinned

ids

(Optional, array) 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 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:

  1. GET /_search
  2. {
  3. "query": {
  4. "pinned": {
  5. "docs": [
  6. {
  7. "_index": "my-index-000001",
  8. "_id": "1"
  9. },
  10. {
  11. "_index": "my-index-000001",
  12. "_id": "4"
  13. },
  14. {
  15. "_index": "my-index-000002",
  16. "_id": "100"
  17. }
  18. ],
  19. "organic": {
  20. "match": {
  21. "description": "iphone"
  22. }
  23. }
  24. }
  25. }
  26. }