# Base64 strings and range

**URL:** <https://discuss.elastic.co/t/base64-strings-and-range/15229>\
**Category:** Elasticsearch\
**Created:** [January 14, 2014, 8:56am UTC](https://discuss.elastic.co/t/base64-strings-and-range/15229 "2014-01-14T08:56:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dunaeth](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dunaeth](https://discuss.elastic.co/u/dunaeth)\
**Post date:** [January 14, 2014, 8:56am UTC](https://discuss.elastic.co/t/base64-strings-and-range/15229/1 "2014-01-14T08:56:15Z")

</div>

Hi,

Would there be any way to analyze base64 string fields so that one can  
execute range queries on them. I want to store IPs (v4 and v6) as base64  
encoded strings and be able to retrieve those within a given range.

--  
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/98b0acb5-c66a-44bb-bd4d-2d7d39a8d5e1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/98b0acb5-c66a-44bb-bd4d-2d7d39a8d5e1%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:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [January 14, 2014, 9:00pm UTC](https://discuss.elastic.co/t/base64-strings-and-range/15229/2 "2014-01-14T21:00:58Z")

</div>

Your client converts IP addresses to base64 strings before it indexes the  
documents, so it must also use the same conversion to a base64 string when  
querying the document.

Ranges are a little more complicated. For example. if you simply encode "9"  
and "111" as strings, then you cannot perform range queries, since "111" is  
less than "0", string-wise. In this case you must do something that ensures  
that "9" is less than "111", typically by creating fixed-length input  
strings before encoding; for example "009" and "111". Now the string  
comparisons will match the intended numeric comparisons.

IP addresses will be more complex. But still, you will need to apply the  
same external conversions in front of your queries that you do in front of  
your indexing.

Brian

--  
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/893f0e01-388c-4350-8b8c-151a06ed8f59%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/893f0e01-388c-4350-8b8c-151a06ed8f59%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:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [January 14, 2014, 9:15pm UTC](https://discuss.elastic.co/t/base64-strings-and-range/15229/3 "2014-01-14T21:15:39Z")

</div>

Quick typing correction:

On Tuesday, January 14, 2014 4:00:58 PM UTC-5, InquiringMind wrote:

> Your client converts IP addresses to base64 strings before it indexes the  
> documents, so it must also use the same conversion to a base64 string when  
> querying the document.
> 
> Ranges are a little more complicated. For example. if you simply encode  
> "9" and "111" as strings, then you cannot perform range queries, since _"111"  
> is less than "9"_, string-wise. In this case you must do something that  
> ensures that "9" is less than "111", typically by creating fixed-length  
> input strings before encoding; for example "009" and "111". Now the string  
> comparisons will match the intended numeric comparisons.
> 
> IP addresses will be more complex. But still, you will need to apply the  
> same external conversions in front of your queries that you do in front of  
> your indexing.
> 
> Brian

--  
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/f6055fc2-d753-4f31-a277-aaedf07f61ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f6055fc2-d753-4f31-a277-aaedf07f61ec%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:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [January 14, 2014, 9:40pm UTC](https://discuss.elastic.co/t/base64-strings-and-range/15229/4 "2014-01-14T21:40:53Z")

</div>

IPv4 can be encoded to unsigned long (32bit), where range search is  
available.

IPv6 is harder as it is 128bit, where no Java type is available except  
something like BigDecimal, and no range search.

Do not use base64, it is impossible for executing range queries on it.

Jörg

--  
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/CAKdsXoHfTMUiXFhmup\_FfBZFYvTRZRUqop51gAy\_ZxkghKnF1Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHfTMUiXFhmup_FfBZFYvTRZRUqop51gAy_ZxkghKnF1Q%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:** ![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, 1:56am UTC](https://discuss.elastic.co/t/base64-strings-and-range/15229/5 "2017-07-06T01:56:47Z")

</div>


