# RGB Color search

**URL:** <https://discuss.elastic.co/t/rgb-color-search/13987>\
**Category:** Elasticsearch\
**Created:** [October 17, 2013, 1:35pm UTC](https://discuss.elastic.co/t/rgb-color-search/13987 "2013-10-17T13:35:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dantuff](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@dantuff](https://discuss.elastic.co/u/dantuff)\
**Post date:** [October 17, 2013, 1:35pm UTC](https://discuss.elastic.co/t/rgb-color-search/13987/1 "2013-10-17T13:35:30Z")

</div>

I have RGB color values stored in my index.

color: [  
{  
red: 50  
green: 73  
blue: 93  
}]

I need to be able to find documents in the index that are the the closest  
color to the RGB values in a request using Euclidean distance, what is the  
best way to achieve this in ElasticSearch?

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Andrej](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@Andrej](https://discuss.elastic.co/u/Andrej)\
**Post date:** [October 17, 2013, 1:59pm UTC](https://discuss.elastic.co/t/rgb-color-search/13987/2 "2013-10-17T13:59:23Z")

</div>

You could use function score query and provide calculation of distance as  
script, maybe?

Am Donnerstag, 17. Oktober 2013 15:35:30 UTC+2 schrieb dan:

> I have RGB color values stored in my index.
> 
> color: [  
> {  
> red: 50  
> green: 73  
> blue: 93  
> }]
> 
> I need to be able to find documents in the index that are the the closest  
> color to the RGB values in a request using Euclidean distance, what is the  
> best way to achieve this in Elasticsearch?

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 17, 2013, 2:25pm UTC](https://discuss.elastic.co/t/rgb-color-search/13987/3 "2013-10-17T14:25:18Z")

</div>

Hmmm. I love that use case.  
Still wondering if color should be a specific type such as geo\_point?

Anyhow, I would love to hear how you implement it.

## Best

David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 17 oct. 2013 à 15:59, Andrej Rosenheinrich [andrej.rosenheinrich@unister.de](mailto:andrej.rosenheinrich@unister.de) a écrit :

> You could use function score query and provide calculation of distance as script, maybe?
> 
> Am Donnerstag, 17. Oktober 2013 15:35:30 UTC+2 schrieb dan:  
> I have RGB color values stored in my index.
> 
> color: [  
> {  
> red: 50  
> green: 73  
> blue: 93  
> }]
> 
> I need to be able to find documents in the index that are the the closest color to the RGB values in a request using Euclidean distance, what is the best way to achieve this in Elasticsearch?
> 
> --  
> 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).  
> 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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dantuff](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@dantuff](https://discuss.elastic.co/u/dantuff)\
**Post date:** [October 17, 2013, 7:45pm UTC](https://discuss.elastic.co/t/rgb-color-search/13987/4 "2013-10-17T19:45:17Z")

</div>

Thanks, this seems like a good way to do it.

I'm trying to get a simple example of the script\_score working, but it  
seems like my syntax is wrong;

{  
"query" : {  
"query\_string" : {  
"query" : "_:_"  
},  
"script\_score": {  
"lang": "lang",  
"script":"\_score \* 5"  
}  
}  
}

Are there any examples anywhere?

On Thursday, October 17, 2013 2:59:23 PM UTC+1, Andrej Rosenheinrich wrote:

> You could use function score query and provide calculation of distance as  
> script, maybe?
> 
> Am Donnerstag, 17. Oktober 2013 15:35:30 UTC+2 schrieb dan:
> 
> > I have RGB color values stored in my index.
> > 
> > color: [  
> > {  
> > red: 50  
> > green: 73  
> > blue: 93  
> > }]
> > 
> > I need to be able to find documents in the index that are the the closest  
> > color to the RGB values in a request using Euclidean distance, what is the  
> > best way to achieve this in Elasticsearch?

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 17, 2013, 7:51pm UTC](https://discuss.elastic.co/t/rgb-color-search/13987/5 "2013-10-17T19:51:02Z")

</div>

Have a look at function score: [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)

## It should help

David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 17 oct. 2013 à 21:45, dan [dan.tuffery@gmail.com](mailto:dan.tuffery@gmail.com) a écrit :

> Thanks, this seems like a good way to do it.
> 
> I'm trying to get a simple example of the script\_score working, but it seems like my syntax is wrong;
> 
> {  
> "query" : {  
> "query\_string" : {  
> "query" : "_:_"  
> },  
> "script\_score": {  
> "lang": "lang",  
> "script":"\_score \* 5"  
> }  
> }  
> }
> 
> Are there any examples anywhere?
> 
> On Thursday, October 17, 2013 2:59:23 PM UTC+1, Andrej Rosenheinrich wrote:  
> You could use function score query and provide calculation of distance as script, maybe?
> 
> Am Donnerstag, 17. Oktober 2013 15:35:30 UTC+2 schrieb dan:  
> I have RGB color values stored in my index.
> 
> color: [  
> {  
> red: 50  
> green: 73  
> blue: 93  
> }]
> 
> I need to be able to find documents in the index that are the the closest color to the RGB values in a request using Euclidean distance, what is the best way to achieve this in Elasticsearch?
> 
> --  
> 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).  
> 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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dantuff](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@dantuff](https://discuss.elastic.co/u/dantuff)\
**Post date:** [October 17, 2013, 8:06pm UTC](https://discuss.elastic.co/t/rgb-color-search/13987/6 "2013-10-17T20:06:11Z")

</div>

Thanks David, that link is giving me a 404

On Thursday, October 17, 2013 8:51:02 PM UTC+1, David Pilato wrote:

> Have a look at function score:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.htm)  
> l
> 
> ## It should help
> 
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 17 oct. 2013 à 21:45, dan \<[dan.t...@gmail.com](mailto:dan.t...@gmail.com) \<javascript:\>\> a écrit :
> 
> Thanks, this seems like a good way to do it.
> 
> I'm trying to get a simple example of the script\_score working, but it  
> seems like my syntax is wrong;
> 
> {  
> "query" : {  
> "query\_string" : {  
> "query" : "_:_"  
> },  
> "script\_score": {  
> "lang": "lang",  
> "script":"\_score \* 5"  
> }  
> }  
> }
> 
> Are there any examples anywhere?
> 
> On Thursday, October 17, 2013 2:59:23 PM UTC+1, Andrej Rosenheinrich wrote:
> 
> > You could use function score query and provide calculation of distance as  
> > script, maybe?
> > 
> > Am Donnerstag, 17. Oktober 2013 15:35:30 UTC+2 schrieb dan:
> > 
> > > I have RGB color values stored in my index.
> > > 
> > > color: [  
> > > {  
> > > red: 50  
> > > green: 73  
> > > blue: 93  
> > > }]
> > > 
> > > I need to be able to find documents in the index that are the the  
> > > closest color to the RGB values in a request using Euclidean distance, what  
> > > is the best way to achieve this in Elasticsearch?
> 
> --  
> 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:\>.  
> 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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 18, 2013, 5:18am UTC](https://discuss.elastic.co/t/rgb-color-search/13987/7 "2013-10-18T05:18:30Z")

</div>

URL is correct but the link I provided when you click on it is wrong.

> **[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.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 17 oct. 2013 à 22:06, dan [dan.tuffery@gmail.com](mailto:dan.tuffery@gmail.com) a écrit :

Thanks David, that link is giving me a 404

> On Thursday, October 17, 2013 8:51:02 PM UTC+1, David Pilato wrote:  
> Have a look at function score: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)
> 
> ## It should help
> 
> David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> @dadoonet | @elasticsearchfr | @scrutmydocs
> 
> > Le 17 oct. 2013 à 21:45, dan [dan.t...@gmail.com](mailto:dan.t...@gmail.com) a écrit :
> > 
> > Thanks, this seems like a good way to do it.
> > 
> > I'm trying to get a simple example of the script\_score working, but it seems like my syntax is wrong;
> > 
> > {  
> > "query" : {  
> > "query\_string" : {  
> > "query" : "_:_"  
> > },  
> > "script\_score": {  
> > "lang": "lang",  
> > "script":"\_score \* 5"  
> > }  
> > }  
> > }
> > 
> > Are there any examples anywhere?
> > 
> > > On Thursday, October 17, 2013 2:59:23 PM UTC+1, Andrej Rosenheinrich wrote:  
> > > You could use function score query and provide calculation of distance as script, maybe?
> > > 
> > > Am Donnerstag, 17. Oktober 2013 15:35:30 UTC+2 schrieb dan:
> > > 
> > > > I have RGB color values stored in my index.
> > > > 
> > > > color: [  
> > > > {  
> > > > red: 50  
> > > > green: 73  
> > > > blue: 93  
> > > > }]
> > > > 
> > > > I need to be able to find documents in the index that are the the closest color to the RGB values in a request using Euclidean distance, what is the best way to achieve this in Elasticsearch?
> > 
> > --  
> > 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).  
> > 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).  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood1/32/101255_2.png) [@Mark\_Harwood1](https://discuss.elastic.co/u/Mark_Harwood1)\
**Post date:** [October 18, 2013, 1:18pm UTC](https://discuss.elastic.co/t/rgb-color-search/13987/8 "2013-10-18T13:18:23Z")

</div>

There's an implementation of a colour distance algorithm here:  
[http://compuphase.com/cmetric.htm](http://compuphase.com/cmetric.htm)

I coded it up as a Lucene query some time ago (don't have the source to  
hand currently) and results were OK but had some oddities.  
I ended up thinking that a data-gathering exercise via Mechanical Turk or  
similar might be a useful exercise to train a better model that accounts  
for the quirks in human perception.

Cheers  
Mark

--  
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).  
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:11am UTC](https://discuss.elastic.co/t/rgb-color-search/13987/9 "2017-07-06T02:11:45Z")

</div>


