# Problem with searching binary data

**URL:** https://discuss.elastic.co/t/problem-with-searching-binary-data/43616
**Category:** Elasticsearch
**Created:** [March 7, 2016, 4:35am UTC](https://discuss.elastic.co/t/problem-with-searching-binary-data/43616 "2016-03-07T04:35:34Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Jayant](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@Jayant](https://discuss.elastic.co/u/Jayant)
#### Post date: [March 7, 2016, 4:35am UTC](https://discuss.elastic.co/t/problem-with-searching-binary-data/43616/1 "2016-03-07T04:35:34Z")

</div>

Hi I am new to ES, I am trying to store binary values such as 00001111 by converting them with Base64 encoding into ES.  
Steps I did to put the data into ES

```
`PUT /my_store2
{
    "mappings" : {
        "products" : {
            "properties" : {
                "productID" : {
                    "type" : "binary",
                    "index" : "analyzed" 
                }
            }
        }
    }
}`

POST /my_store2/products/_bulk
{ "index": { "_id": 8 }}
{ "productID" : "MDAwMTEwMDE="}

```

When I searched using this query I did not get any results. Am I doing wrong anywhere while storing the data into ES.

```
GET /my_store2/products/_search
{
"query": {
    "query_string": {
       "default_field": "productID",
       "query": "MDAwMTEwMDE="
    }
}
} 

```

Any help on this will be much appreciated. Also, using the binary datatype to store the "11110000" binary values into ES is the ideal way or are there any better ways of storing the binary values into ES and be able to search them.

---

<div class="post-metadata">

### Author: ![Jayant](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@Jayant](https://discuss.elastic.co/u/Jayant)
#### Post date: [March 7, 2016, 4:41am UTC](https://discuss.elastic.co/t/problem-with-searching-binary-data/43616/2 "2016-03-07T04:41:12Z")

</div>

If possible, can someone provide an example to store and search the binary data in ES.

---

<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: [March 7, 2016, 6:04am UTC](https://discuss.elastic.co/t/problem-with-searching-binary-data/43616/3 "2016-03-07T06:04:07Z")

</div>

I would try to not analyze the content.

Does it change anything?

---

<div class="post-metadata">

### Author: ![Jayant](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@Jayant](https://discuss.elastic.co/u/Jayant)
#### Post date: [March 7, 2016, 7:38pm UTC](https://discuss.elastic.co/t/problem-with-searching-binary-data/43616/4 "2016-03-07T19:38:09Z")

</div>

I tried that way too, it still doesn't change anything.

---

<div class="post-metadata">

### Author: ![Peter\_van\_der\_Weerd](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@Peter\_van\_der\_Weerd](https://discuss.elastic.co/u/Peter_van_der_Weerd)
#### Post date: [March 7, 2016, 8:13pm UTC](https://discuss.elastic.co/t/problem-with-searching-binary-data/43616/5 "2016-03-07T20:13:58Z")

</div>

According to the docs a binary field is not searchable. (Didn't try though...)  
But, for such a small field: why choose binary and not just string?

---

<div class="post-metadata">

### Author: ![Jayant](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@Jayant](https://discuss.elastic.co/u/Jayant)
#### Post date: [March 7, 2016, 8:46pm UTC](https://discuss.elastic.co/t/problem-with-searching-binary-data/43616/6 "2016-03-07T20:46:55Z")

</div>

I have a field which I want it to hide it from the users - "more like a metadata field" used for the binary operations.

Say " get me all the products which start with a but of certain type whose ID is both "VegSection" and "Grocery"

```
GET /my_store3/products/_search
{
    "query": {
        "filtered": {
           "query": {
            "query_string": {
           "default_field": "productName_text",
            "query": "a*"
        }
           },
           "filter": {
               "term": {
                  "productID": "MDAwMTEwMDE"
               }
           }
        } 
       
    }
    
}
```

---

<div class="post-metadata">

### Author: ![Peter\_van\_der\_Weerd](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@Peter\_van\_der\_Weerd](https://discuss.elastic.co/u/Peter_van_der_Weerd)
#### Post date: [March 7, 2016, 9:23pm UTC](https://discuss.elastic.co/t/problem-with-searching-binary-data/43616/7 "2016-03-07T21:23:18Z")

</div>

Yeah, but what I mean is: why not mapping it as a string. So, you supply the base64 string in the \_source and then index that field as a string. From what I see in your samples, you work with the string value like 'MDAwMTEwMDE'...

---

<div class="post-metadata">

### Author: ![Jayant](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@Jayant](https://discuss.elastic.co/u/Jayant)
#### Post date: [March 7, 2016, 9:28pm UTC](https://discuss.elastic.co/t/problem-with-searching-binary-data/43616/8 "2016-03-07T21:28:16Z")

</div>

Sorry for my mistake, I shouldn't have mentioned in the query that I was doing the search on the field type. Instead, I was doing the search on all the fields except my meta field.

After the result of the search, I would like to filter them out based on my metadata field.

If I index it as string then my search results might also include my metadata field.

---

<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 5, 2017, 11:10pm UTC](https://discuss.elastic.co/t/problem-with-searching-binary-data/43616/9 "2017-07-05T23:10:35Z")

</div>


