Bit arrays usage and filtering in Elasticsearch

孤街浪徒 提交于 2019-12-12 13:05:54

问题


I have a bit array. And I want to filter based on if certain bits are ON or OFF. Looking at the Elasticsearch 2.3 docs, I don't see anything about bitarrays.

But it seems I can use an Array of Booleans or a Binary field.

Example: Let's say I have 2 documents each with a bit array field. Doc1 has 011100 and Doc2 has 00001 in that field. And I want to filter by 011000 which in this case only gives Doc1.

Any ideas how to do this in Elasticsearch?

Thanks you.

Edit: Another idea:

If I turn the bit array into many Bool fields, then it works. The doc might look ugly but it works. Basically if the bit array is 32 bit, then I will have 32 bool fields. Is that the best way to implement this?


回答1:


if you could change it to an array containing the bit-index which are set. That is 011100 would be[ 1 , 2 ,3 ] and then use a terms query to do an or or a must query for and

Example :

a)  document with "111" 

put test/test/1
{
   "bit_position" : [
        1,
        2,
        3
    ]
}

b) document with 010
put test/test/2
{
   "bit_position": [
      2
   ]
}

c) or-ing with 101

post test/_search
{
    "query": {
        "terms": {
           "bit_position": [
              1,
              3
           ]
        }
    }
}


来源:https://stackoverflow.com/questions/39110962/bit-arrays-usage-and-filtering-in-elasticsearch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!