API version: dev

---

# Text prefix search

This example uses Elasticsearch's [`prefix` query](https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-prefix-query)
to find all elements whose `name` starts with the string `blu`, and are accessible to the user.\
Results are then [hydrated](/reference/search/element-hydration.md), i.e. transformed into a collection response.

**Note**: `prefix` is a term-level query, so it is matched against the exact indexed value rather than an analyzed
text field - similar to [exact keyword matching](/reference/search/elasticsearch-query-dsl-mixin/exact-keyword-matching.md),
`name.keyword` should be preferred over `name` for reliable prefix matches on `text` fields.

```bash
curl -X POST \
  -H 'Authorization: Bearer secret-token:PIPeJGUt7c00ENn8a5uDlc' \
  -H 'Content-Type: application/json' \
  -d '{
        "debug": true,
        "steps": [
          {
            "type": "elasticsearch-query-dsl-mixin",
            "query": {
              "prefix": {
                "name": {
                  "value": "blu"
                }
              }
            }
          },
          {
            "type": "element-hydration"
          }
        ]
      }' \
  https://api.example.com/search
```

##### Response Body

```json
{
  "type": "_SearchResultResponse",
  "results": [
    {
      "type": "Tag",
      "id": "79ca27e5-93bb-43e6-a76b-096ea45e2e8e",
      "data": {
        "description": "Blue is one of the three primary colours in the RGB (additive) colour model, as well as in the RYB c...",
        "created": "2025-09-25T18:35:26+00:00",
        "updated": "2025-09-25T18:35:26+00:00",
        "name": "blue",
        "color": "#4363d8",
        "scenario": "general.botanicExample",
        "link": "https://en.wikipedia.org/wiki/Blue"
      }
    },
    {
      "type": "Plant",
      "id": "83b35321-4a91-4e9f-a49b-66d718c32ba7",
      "data": {
        "images": [
          {
            "description": "Mertensia virginica Virginia Bluebell seen in Brooklyn Botanic Garden",
            "imageLinkFull": "https://upload.wikimedia.org/wikipedia/commons/3/31/Mertensia_virginica.bbg.jpg",
            "imageLinkThumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Mertensia_virginica.bbg.jpg/960px-Mertensi...",
            "link": "https://en.wikipedia.org/wiki/File:Mertensia_virginica.bbg.jpg"
          },
          {
            "description": "Virginia Bluebells along the Rocky River in Berea, OH. Photo by Geoffrey A. Landis",
            "imageLinkFull": "https://upload.wikimedia.org/wikipedia/commons/6/6f/Virginia_Bluebells_at_Rocky_River.jpg",
            "imageLinkThumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Virginia_Bluebells_at_Rocky_River.jpg/960p...",
            "link": "https://en.wikipedia.org/wiki/File:Virginia_Bluebells_at_Rocky_River.jpg"
          }
        ],
        "created": "2025-09-25T18:35:28+00:00",
        "updated": "2025-09-25T18:35:28+00:00",
        "name": "Bluebell",
        "scenario": "general.botanicExample",
        "scientificName": "M. virginica",
        "link": "https://en.wikipedia.org/wiki/Mertensia_virginica",
        "description": "Mertensia virginica (common names Virginia bluebells,[1] Virginia cowslip,[2] lungwort oysterleaf, R..."
      }
    }
  ],
  "debug": [
    {
      "input": {
        "type": "elasticsearch-query-dsl-mixin",
        "query": {
          "prefix": {
            "name": {
              "value": "blu"
            }
          }
        },
        "parameters": {
          "stepResults": []
        }
      },
      "step-handler": "elasticsearch-query-dsl-mixin (App\\EventSystem\\SearchStep\\EventListener\\ElasticsearchQueryDslMixinSe...",
      "start": 1758825391.494736,
      "indices": "*",
      "combinedQuery": {
        "_source": [
          "_id"
        ],
        "from": 0,
        "size": 25,
        "query": {
          "bool": {
            "must": [
              {
                "prefix": {
                  "name": {
                    "value": "blu"
                  }
                }
              },
              {
                "bool": {
                  "should": [
                    {
                      "terms": {
                        "_groupsWithSearchAccess.keyword": []
                      }
                    },
                    {
                      "term": {
                        "_usersWithSearchAccess.keyword": {
                          "value": "7baba8b7-a6bb-4184-9a9a-925a4d2736b0"
                        }
                      }
                    }
                  ],
                  "minimum_should_match": 1
                }
              }
            ]
          }
        }
      },
      "end": 1758825391.524346,
      "duration": 0.02961
    },
    {
      "input": {
        "type": "element-hydration",
        "query": null,
        "parameters": {
          "stepResults": [
            {
              "elements": [
                {
                  "id": "79ca27e5-93bb-43e6-a76b-096ea45e2e8e",
                  "type": "Tag",
                  "metadata": {
                    "score": 1.0219789
                  }
                },
                {
                  "id": "83b35321-4a91-4e9f-a49b-66d718c32ba7",
                  "type": "Plant",
                  "metadata": {
                    "score": 1.0101794
                  }
                }
              ],
              "totalHits": 2,
              "maxScore": 1.0219789
            }
          ]
        }
      },
      "step-handler": "element-hydration (App\\EventSystem\\SearchStep\\EventListener\\ElementHydrationSearchStepEventListener)",
      "start": 1758825391.524511,
      "accessibleElementIds": [
        "79ca27e5-93bb-43e6-a76b-096ea45e2e8e",
        "83b35321-4a91-4e9f-a49b-66d718c32ba7"
      ],
      "end": 1758825391.541848,
      "duration": 0.017337
    }
  ]
}
```

##### Response Headers

```http
Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: ETag, Location
Allow: GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK
Cache-Control: no-cache, private
Content-Type: application/json; charset=utf-8
Date: Sat, 06 Sep 2025 14:57:35 GMT
Transfer-Encoding: chunked
X-Powered-By: Ember Nexus API
```

Both results have a `name` starting with "blu" - the tag "blue" and the plant "Bluebell".

---

Home: [Ember Nexus API docs](/index.md)

Full site map: [llms.txt](/llms.txt)

Previous: [Query string](/reference/search/elasticsearch-query-dsl-mixin/query-string.md)

Next: [Wildcard search](/reference/search/elasticsearch-query-dsl-mixin/wildcard-search.md)
