Elasticsearch中的位数组使用和过滤 [英] Bit arrays usage and filtering in Elasticsearch

查看:233
本文介绍了Elasticsearch中的位数组使用和过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组。而且我想基于某些位是ON还是关闭来进行过滤。
看看Elasticsearch 2.3文档,我没有看到任何关于bitarrays的信息。



但是我似乎可以使用一个布尔阵列或一个二进制字段。



示例:
假设我有两个文档,每个都有一个位数组字段。 Doc1有011100,Doc2在该领域有00001。而且我想要通过011000进行过滤,在这种情况下,这只能给出Doc1。



任何想法如何在Elasticsearch中执行此操作?



谢谢你。



编辑:另一个想法:



如果我将位阵列变成许多Bool字段,然后它的作品。该文档可能看起来很丑,但它的作品。
基本上如果位数组是32位,那么我将有32个bool字段。这是实现这个的最好方法吗?

解决方案

如果可以将其更改为包含设置的位索引的数组。那就是 011100 将是 [1,2,3] 然后使用 / code>查询以执行必须查询



示例:

  a)文档与111

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

b)文件与010
put test / test / 2
{
bit_position:[
2
]
}

c)or-ing with 101

post test / _search
{
query:{
条款:{
bit_position:[
1,
3
]
}
}
}


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?

解决方案

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
           ]
        }
    }
}

这篇关于Elasticsearch中的位数组使用和过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆