# Ampersand gets stripped out of search query

**URL:** https://discuss.elastic.co/t/ampersand-gets-stripped-out-of-search-query/366511
**Category:** Elastic Search
**Tags:** elastic-app-search
**Created:** [September 13, 2024, 7:06am UTC](https://discuss.elastic.co/t/ampersand-gets-stripped-out-of-search-query/366511 "2024-09-13T07:06:45Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![kudumine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kudumine/32/138227_2.png) [@kudumine](https://discuss.elastic.co/u/kudumine)
#### Post date: [September 13, 2024, 7:06am UTC](https://discuss.elastic.co/t/ampersand-gets-stripped-out-of-search-query/366511/1 "2024-09-13T07:06:46Z")

</div>

I am having an issue where an ampersand is getting stripped out of the search query after the first run.

I had this issue in another spot where I was directly calling an endpoint and grabbing my searchterm from the params and fixed it by getting my search term from `SearchContext`

Now in another spot where the endpoint is hooked up in a connecter and I am grabbing the search query form the searchContext and in this one spot it doesn't work and strips out the ampersand. Everything sending in is correct.

Sending in hardcoded: "this & that"

```auto
const searchQuery = "this & that";

context.driver.setSearchQuery({ searchTerm: searchQuery });

```

Getting "this " returned:

```auto
import { SearchContext } from "@elastic/react-search-ui";

  const context = useContext(SearchContext);
  const searchTerm = context?.driver.state?.searchTerm;

  console.log("searchTerm:", searchTerm);

```

Is there an argument or a way I can get searchui to ignore the ampersand?

---

<div class="post-metadata">

### Author: ![Artem\_Shelkovnikov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/artem_shelkovnikov/32/134322_2.png) [@Artem\_Shelkovnikov](https://discuss.elastic.co/u/Artem_Shelkovnikov)
#### Post date: [September 13, 2024, 12:10pm UTC](https://discuss.elastic.co/t/ampersand-gets-stripped-out-of-search-query/366511/2 "2024-09-13T12:10:01Z")

</div>

Hi @kudumine,

I think this topic might be relevant to you: [Searching with special characters doesn't work](https://discuss.elastic.co/t/searching-with-special-characters-doesnt-work/279631)

---

<div class="post-metadata">

### Author: ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)
#### Post date: [September 13, 2024, 12:11pm UTC](https://discuss.elastic.co/t/ampersand-gets-stripped-out-of-search-query/366511/3 "2024-09-13T12:11:52Z")

</div>

Hey there @kudumine, you should pass in a [custom analyzer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-custom-analyzer.html) that doesn't filter out the special characters you want.

---

<div class="post-metadata">

### Author: ![kudumine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kudumine/32/138227_2.png) [@kudumine](https://discuss.elastic.co/u/kudumine)
#### Post date: [September 13, 2024, 1:01pm UTC](https://discuss.elastic.co/t/ampersand-gets-stripped-out-of-search-query/366511/4 "2024-09-13T13:01:27Z")

</div>

Thank you @kathleen for the response! Is there a way to set up a custom analyzer and pass it in on the front end? Or do you have any more examples of the implementation of that?

Thank you!

---

<div class="post-metadata">

### Author: ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)
#### Post date: [September 13, 2024, 1:25pm UTC](https://discuss.elastic.co/t/ampersand-gets-stripped-out-of-search-query/366511/5 "2024-09-13T13:25:56Z")

</div>

The docs I link show how to set up analyzers, they're part of your mappings and transparent to the frontend.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 11, 2024, 1:26pm UTC](https://discuss.elastic.co/t/ampersand-gets-stripped-out-of-search-query/366511/6 "2024-10-11T13:26:03Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
