范围过滤器不适用于“gt”运算符,但适用于“lt”

2024-04-18

我正在使用弹性搜索来索引我的文档,并希望根据特定属性过滤文档。这是我的代码:

filter.push({
            range: {"audience.ethnicity.asian" : { gt: 50 } }
        })

它不适用于 gt 运算符(发回不一致的结果),但适用于 lt 运算符

filter.push({
                range: {"audience.ethnicity.asian" : { lt: 50 } }
            })

这很有效。我已仔细检查属性值是否为整数。我尝试了很多不同的方法,但似乎无法弄清楚我错过了什么。 映射:

  "audience": {
    "properties": {
      "age": {
        "properties": {
          "13-17": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "18-24": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "25-34": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "35-44": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "45-64": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "eighteen": {
            "type": "long"
          },
          "fortyfive": {
            "type": "long"
          },
          "thirteen": {
            "type": "long"
          },
          "thirtyfive": {
            "type": "long"
          },
          "twentyfive": {
            "type": "long"
          }
        }
      },
      "ages": {
        "properties": {
          "13-17": {
            "type": "float"
          },
          "18-24": {
            "type": "float"
          },
          "25-34": {
            "type": "float"
          },
          "35-44": {
            "type": "float"
          },
          "45-64": {
            "type": "float"
          }
        }
      },
      "ethnicity": {
        "properties": {
          "African American": {
            "type": "float"
          },
          "Asian": {
            "type": "float"
          },
          "Hispanic": {
            "type": "float"
          },
          "White / Caucasian": {
            "type": "float"
          },
          "african": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "asian": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "hispanic": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "white": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      },
      "gender": {
        "properties": {
          "female": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "male": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      },
      "genders": {
        "properties": {
          "FEMALE": {
            "type": "float"
          },
          "MALE": {
            "type": "float"
          }
        }
      },
      "gendersPerAge": {
        "properties": {
          "13-17": {
            "properties": {
              "FEMALE": {
                "type": "float"
              },
              "MALE": {
                "type": "float"
              }
            }
          },
          "18-24": {
            "properties": {
              "FEMALE": {
                "type": "float"
              },
              "MALE": {
                "type": "float"
              }
            }
          },
          "25-34": {
            "properties": {
              "FEMALE": {
                "type": "float"
              },
              "MALE": {
                "type": "float"
              }
            }
          },
          "35-44": {
            "properties": {
              "FEMALE": {
                "type": "float"
              },
              "MALE": {
                "type": "float"
              }
            }
          },
          "45-64": {
            "properties": {
              "FEMALE": {
                "type": "float"
              },
              "MALE": {
                "type": "float"
              }
            }
          }
        }
      }
    }
  }          "audience": {
    "properties": {
      "age": {
        "properties": {
          "13-17": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "18-24": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "25-34": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "35-44": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "45-64": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "eighteen": {
            "type": "long"
          },
          "fortyfive": {
            "type": "long"
          },
          "thirteen": {
            "type": "long"
          },
          "thirtyfive": {
            "type": "long"
          },
          "twentyfive": {
            "type": "long"
          }
        }
      },
      "ages": {
        "properties": {
          "13-17": {
            "type": "float"
          },
          "18-24": {
            "type": "float"
          },
          "25-34": {
            "type": "float"
          },
          "35-44": {
            "type": "float"
          },
          "45-64": {
            "type": "float"
          }
        }
      },
      "ethnicity": {
        "properties": {
          "African American": {
            "type": "float"
          },
          "Asian": {
            "type": "float"
          },
          "Hispanic": {
            "type": "float"
          },
          "White / Caucasian": {
            "type": "float"
          },
          "african": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "asian": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "hispanic": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "white": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      },
      "gender": {
        "properties": {
          "female": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "male": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      },
      "genders": {
        "properties": {
          "FEMALE": {
            "type": "float"
          },
          "MALE": {
            "type": "float"
          }
        }
      },
      "gendersPerAge": {
        "properties": {
          "13-17": {
            "properties": {
              "FEMALE": {
                "type": "float"
              },
              "MALE": {
                "type": "float"
              }
            }
          },
          "18-24": {
            "properties": {
              "FEMALE": {
                "type": "float"
              },
              "MALE": {
                "type": "float"
              }
            }
          },
          "25-34": {
            "properties": {
              "FEMALE": {
                "type": "float"
              },
              "MALE": {
                "type": "float"
              }
            }
          },
          "35-44": {
            "properties": {
              "FEMALE": {
                "type": "float"
              },
              "MALE": {
                "type": "float"
              }
            }
          },
          "45-64": {
            "properties": {
              "FEMALE": {
                "type": "float"
              },
              "MALE": {
                "type": "float"
              }
            }
          }
        }
      }
    }
  }

在您的映射中,audience.ethnicity.asian字段的类型为文本,因此范围查询正在执行词汇范围比较代替数值范围比较.

在数字上,123 > 50,但在词汇上 123

我不确定你是否可以使用audience.ethnicity.Asian字段,它是一个浮点数。如果没有,您需要更改映射audience.ethnicity.asian为数字类型 (integer, float等)并重新索引您的数据。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

范围过滤器不适用于“gt”运算符,但适用于“lt” 的相关文章

随机推荐

  • 美汤元素如何添加元素

    如果我有这样的 bs4 元素 它被称为tab window uls 1 ul li b Cut b Sits low on the waist li li b Fit b Skinny through the leg li li b Leg
  • 使用 C++ 删除文本文件中重复行的内存有效方法

    使用 C 删除大型文本文件中的重复行的最有效内存方法是什么 让我澄清一下 我不是要求代码 只是最好的方法 不保证重复的行是相邻的 我意识到针对最小内存使用进行优化的方法会导致速度变慢 但这是我的限制 因为文件太大 我会对每一行进行散列 然后
  • 如何在xamarin表单中使用单选按钮

    创建注册页面 我需要从用户那里获取以下数据 名 姓 Username Email Password 出生日期 Gender 用户角色 对于最后两个参数 我无法找到如何在 Xamarin Forms 中使用单选按钮 以下是我的注册页面代码
  • C#:具有构造函数的泛型类型?

    我有以下 C 测试代码 class MyItem MyItem int a class MyContainer lt T gt where T MyItem new public void CreateItem T oItem new T
  • 如何在 ngFor 循环中创建变量?

    我试图找出如何在ngFor loop 我有一个这样的循环 td a href getBuild branch prod url getBuild branch prod status a td 您可以看到getBuild必须重复多次调用 在
  • setContentView 执行期间黑屏

    我有一个MainActivity 有时 当它加载时 我会观察到黑屏一秒钟 我测量了操作的时间onCreate方法 发现花费了超过一秒的时间setContentView R layout main screen 我更喜欢显示上一个屏幕 在我的
  • 检测新的网络连接(linux-server)及其在java中的状态

    java 有什么方法可以检测到我刚刚插入有线网络 并监控它的带宽吗 我正在使用linux 如果这很重要的话 为了简单起见并且不使用本机代码 您可以尝试使用java net 网络接口 http java sun com javase 6 do
  • SpriteKit - 获取最近的节点

    有没有办法获得距离节点最近的节点 我正要编写一个方法来迭代所有节点并计算距离等 但想知道是否有更好的方法 我有 30 个节点 需要距离这 30 个节点中的每一个最近的 2 个节点 如果有意义的话 从 iOS 10 开始 您可以使用空间分区功
  • 在调用 f:ajax 侦听器之前和之后执行 JavaScript

    有一种简单的方法可以在调用之前和之后调用 JavaScript 操作
  • 扩展方法的空目标

    public static IFoo Bar
  • Linq to NHibernate 生成到同一个表的多个联接

    当我在 select 和 where 子句中引用同一个表时 linq to Nhibernate 会生成两个连接 一个用于 select 一个用于 where IE from child in Session Query
  • 比较 Django 中的日期和日期时间

    我有一个带有日期时间字段的模型 class MyModel models Model created models DateTimeField auto now True 我想获取今天创建的所有记录 我试过 MyModel objects
  • window.console 可以被覆盖吗?它是只读的吗?

    我用consolejavascript 中的对象用于调试 并希望覆盖它以便在移动浏览器中使用此类功能 但是 我无法理解以下 MDN 文档 Window console 只读属性返回对 Console 对象 提供将信息记录到控制台的方法 浏览
  • 如何通过 SystemJs 在 Angular2 中使用时刻时区

    我正在使用 Angular2 通过Angular2 种子 https github com mgechev angular2 seed 使用 SystemJS 并尝试加载时刻时区 http momentjs com timezone doc
  • 使用片段共享过渡时返回过渡无法正常工作

    我有2个碎片ListMovieFragment and DetailMovieFragment 我有一个界面ListMovieFragment是在MainActivity 我正在使用共享元素转换 当我单击图像视图时ListMovieFrag
  • 有效地构建具有给定汉明距离的单词图

    我想从单词列表中构建一个图表汉明距离 https en wikipedia org wiki Hamming distance 比如说 1 或者换句话说 如果两个单词仅与一个字母不同 lol 假设您将字典存储在set 以便查找是O 1 平均
  • 在 Delphi 2009 中挂钩堆栈跟踪

    Delphi 2009 中的 Exception 类获得了许多新功能 其中许多与获取堆栈跟踪有关 property堆栈跟踪 string read获取堆栈跟踪 property堆栈信息 指针readFStackInfo 类变量获取异常堆栈信
  • Windows 上的 unbuffer 程序相当于什么?

    你好根据这个帖子 https unix stackexchange com a 25375 unbuffer通过伪终端 pty 连接到命令 这使得系统将其视为交互式进程 因此不使用任何 stdout 缓冲 我想在 Windows 上使用这个
  • 寻找 Maven 工件:Spring + Hibernate + JPA

    我是 Maven 新手 有以下 2 个关于 Maven 的问题 我正在寻找一个包含 Spring Hibernate JPA 的 Maven 工件 我发现的唯一一种是与 Flex 混合的 现在 我想保持简单 并且不想处理 Flex 增加的复
  • 范围过滤器不适用于“gt”运算符,但适用于“lt”

    我正在使用弹性搜索来索引我的文档 并希望根据特定属性过滤文档 这是我的代码 filter push range audience ethnicity asian gt 50 它不适用于 gt 运算符 发回不一致的结果 但适用于 lt 运算符