简体   繁体   English

使用Elasticsearch对子字段数组进行范围查询

[英]Range query on subfield array with elasticsearch

I'm trying to get all the services with a code different than 0, I don't find any way to do it without doing multiple queries. 我正在尝试使用不等于0的代码来获取所有服务,如果不执行多个查询,我将找不到任何方法。 Here's the data i'm trying to query, thanks in advance for the help 这是我要查询的数据,在此先感谢您的帮助

      "hits": [
     {
        "_index": "database_index",
        "_type": "system",
        "_id": "AV03gG7B3dd3_xKqi09H",
        "_score": 1,
        "_source": {
           "name_id": "BOX",
           "room_id": "63190",
           "event": "SysMonitor",
           "data": {
              "ip": "192.168.60.25 \n",
              "ns": "192.168.0.1\n",
              "uptime": "3:12"
           },
           "services": {
              "apache2": 1,
              "gw-flash": 0,
              "appmgr": 0,
              "watchdog": 2,
              "gui": 0,
              "usb": 0,
              "internet": 0
           },

This is a classic fulltext search example, where one could write a very complicated query to cover this or you could optimize this on index time and thus have very cheap queries. 这是一个经典的全文搜索示例,其中您可以编写一个非常复杂的查询来解决此问题,或者您可以在索引时间对其进行优化,从而获得非常便宜的查询。 If you change your data model to have a field that contains all the services that have a value of 0 or 1 , you could easily search for that, ie 如果将数据模型更改为具有包含所有值为01的服务的字段,则可以轻松地进行搜索,即

services_zero: [gwflash, appmgr]
services_one: [ apache2 ]

Suddenly your query can easily search or aggregate against those fields. 突然,您的查询可以轻松地针对这些字段进行搜索或汇总。

Not saying that this will perfectly fit your use-case, but I think it is worth to rethink the data modelling strategy here. 并不是说这将完全适合您的用例,但我认为值得在这里重新考虑数据建模策略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM