按尺寸搜索对象类型字段弹性搜索 [英] Search by size of object type field elastic search

查看:131
本文介绍了按尺寸搜索对象类型字段弹性搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的映射:

{
  "post": {
    "properties": {
      "author_gender": {
        "type": "string",
        "index": "not_analyzed",
        "omit_norms": true,
        "index_options": "docs"
      },
      "author_link": {
        "type": "string",
        "index": "no"
      },
      "content": {
        "type": "string"
      },
      "mentions": {
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "profile_image_url": {
            "type": "string"
          },
          "screen_name": {
            "type": "string"
          }
        }
      }
   }
}

我需要搜索提及对象的大小。我已经尝试过:

I need to search by the size of the mentions object. I have tried this:

{
  "filter": {
    "script": {
      "script": "doc['mentions'].values.length == 2"
    }
  }
}

这不工作。发送错误


嵌套:ElasticSearchIllegalArgumentException [在类型[post]]映射中找不到
[提及] / p>

nested: ElasticSearchIllegalArgumentException[No field found for [mentions] in mapping with types [post]];

我也尝试用 doc ['mentions.id']替换脚本部分。value.length = = 2 。它也是错误的

I have also tried replacing the script part with doc['mentions.id'].value.length == 2. It is also erroring


嵌套:ArrayIndexOutOfBoundsException [10];

nested: ArrayIndexOutOfBoundsException[10];

如何查询具有的记录对象大小2?

How to query records with mentions object size 2 ?

推荐答案

弹性搜索指南建议对对象使用size()而不是length。所以尝试这样:

The elasticsearch guide recommends using size() instead of length for objects. So try this:

{
 "filter": {
   "script": {
     "script": "doc['mentions.id'].values.size() == 2"
    }
  }
}

最好的。

这篇关于按尺寸搜索对象类型字段弹性搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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