# Replace in elasticsearch query

**URL:** <https://discuss.elastic.co/t/replace-in-elasticsearch-query/14696>\
**Category:** Elasticsearch\
**Created:** [December 4, 2013, 9:31am UTC](https://discuss.elastic.co/t/replace-in-elasticsearch-query/14696 "2013-12-04T09:31:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vallabh](https://avatars.discourse-cdn.com/v4/letter/v/e8c25b/32.png) [@vallabh](https://discuss.elastic.co/u/vallabh)\
**Post date:** [December 4, 2013, 9:31am UTC](https://discuss.elastic.co/t/replace-in-elasticsearch-query/14696/1 "2013-12-04T09:31:15Z")

</div>

Dear All,

Can i use REPLACE function in elasticsearch query like mysql.

Mysql query:  
select id,name from jos\_artist\_details where REPLACE(name, ' ', '')  
= REPLACE('lady gaga',' ','');

Elastic search query:  
$result = $es-\>search(array(  
"query" =\> array(  
"dis\_max" =\> array(  
"queries" =\> array(  
0 =\> array(  
"field" =\> array(  
"name" =\> 'lady gaga'  
)  
)  
)  
)  
),  
"from" =\> 0,  
"size" =\> 100000,  
"sort" =\> array (  
"\_score"  
)  
)  
);

Any suggestion is highly appreciated!!

Vallabh

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d0be8ab5-5759-4e32-a973-5733e72e0dbf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d0be8ab5-5759-4e32-a973-5733e72e0dbf%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 4, 2013, 1:31pm UTC](https://discuss.elastic.co/t/replace-in-elasticsearch-query/14696/2 "2013-12-04T13:31:42Z")

</div>

Hey,

you could use a script field for this, if you really need to. However this  
might be quite a performance killer (like it is in SQL) - data manipulation  
should be done at index time, not at query time.

See

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

--Alex

On Wed, Dec 4, 2013 at 10:31 AM, Vallabh Bothre [vallabh.bothre@gmail.com](mailto:vallabh.bothre@gmail.com)wrote:

> Dear All,
> 
> Can i use REPLACE function in elasticsearch query like mysql.
> 
> Mysql query:  
> select id,name from jos\_artist\_details where REPLACE(name, ' ', '')  
> = REPLACE('lady gaga',' ','');
> 
> Elastic search query:  
> $result = $es-\>search(array(  
> "query" =\> array(  
> "dis\_max" =\> array(  
> "queries" =\> array(  
> 0 =\> array(  
> "field" =\> array(  
> "name" =\> 'lady gaga'  
> )  
> )  
> )  
> )  
> ),  
> "from" =\> 0,  
> "size" =\> 100000,  
> "sort" =\> array (  
> "\_score"  
> )  
> )  
> );
> 
> Any suggestion is highly appreciated!!
> 
> Vallabh
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/d0be8ab5-5759-4e32-a973-5733e72e0dbf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d0be8ab5-5759-4e32-a973-5733e72e0dbf%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9knXgHs6iJM1Ga\_kQkHQkp2aKB3r5WR\_Qqw2bvV3h8tg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9knXgHs6iJM1Ga_kQkHQkp2aKB3r5WR_Qqw2bvV3h8tg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![vallabh](https://avatars.discourse-cdn.com/v4/letter/v/e8c25b/32.png) [@vallabh](https://discuss.elastic.co/u/vallabh)\
**Post date:** [December 4, 2013, 2:07pm UTC](https://discuss.elastic.co/t/replace-in-elasticsearch-query/14696/3 "2013-12-04T14:07:47Z")

</div>

Thanks Alex

On Wednesday, December 4, 2013 7:01:42 PM UTC+5:30, Alexander Reelsen wrote:

> Hey,
> 
> you could use a script field for this, if you really need to. However this  
> might be quite a performance killer (like it is in SQL) - data manipulation  
> should be done at index time, not at query time.
> 
> See  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-script-fields.html)
> 
> --Alex
> 
> On Wed, Dec 4, 2013 at 10:31 AM, Vallabh Bothre \<[vallabh...@gmail.com](mailto:vallabh...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Dear All,
> > 
> > Can i use REPLACE function in elasticsearch query like mysql.
> > 
> > Mysql query:  
> > select id,name from jos\_artist\_details where REPLACE(name, ' ', '')  
> > = REPLACE('lady gaga',' ','');
> > 
> > Elastic search query:  
> > $result = $es-\>search(array(  
> > "query" =\> array(  
> > "dis\_max" =\> array(  
> > "queries" =\> array(  
> > 0 =\> array(  
> > "field" =\> array(  
> > "name" =\> 'lady gaga'  
> > )  
> > )  
> > )  
> > )  
> > ),  
> > "from" =\> 0,  
> > "size" =\> 100000,  
> > "sort" =\> array (  
> > "\_score"  
> > )  
> > )  
> > );
> > 
> > Any suggestion is highly appreciated!!
> > 
> > Vallabh
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/d0be8ab5-5759-4e32-a973-5733e72e0dbf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d0be8ab5-5759-4e32-a973-5733e72e0dbf%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0d4f9a6f-3f69-4095-bc3f-be4be80b5ebf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0d4f9a6f-3f69-4095-bc3f-be4be80b5ebf%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:03am UTC](https://discuss.elastic.co/t/replace-in-elasticsearch-query/14696/4 "2017-07-06T02:03:17Z")

</div>


