elasticsearch elasticsearch-搜索小数点后2位以上的数字,elasticsearch,elasticsearch" /> elasticsearch elasticsearch-搜索小数点后2位以上的数字,elasticsearch,elasticsearch" />

elasticsearch elasticsearch-搜索小数点后2位以上的数字

elasticsearch elasticsearch-搜索小数点后2位以上的数字,elasticsearch,elasticsearch,如何在elasticsearch中搜索数值字段超过2位小数的文档 我的映射如下: { "items": { "mappings": { "item": { "properties": { "id": { "type": "long" }, "item": { "type": "

如何在elasticsearch中搜索数值字段超过2位小数的文档

我的映射如下:

{
   "items": {
      "mappings": {
         "item": {
            "properties": {
               "id": {
                  "type": "long"
               },
               "item": {
                  "type": "string"
               },
               "price": {
                  "type": "double"
               }
            }
         }
      }
   }
}
{
  "id": 1,
  "item": "abc",
  "price": 1234.567
}
文件样本如下:

{
   "items": {
      "mappings": {
         "item": {
            "properties": {
               "id": {
                  "type": "long"
               },
               "item": {
                  "type": "string"
               },
               "price": {
                  "type": "double"
               }
            }
         }
      }
   }
}
{
  "id": 1,
  "item": "abc",
  "price": 1234.567
}
尝试以下查询时,我会收到NumberFormatException: 获取项目/\u搜索

{
    "query": {
        "bool": {
            "must": {
                "regexp": {"price": "[0-9]*\\.[0-9]{3,}"}
            }
        }
    }
}

很遗憾,您不能在数字字段上使用正则表达式

一种可能的解决方法是使用
脚本
查询/过滤器,如下所示。它所做的只是检查在这段时间后有多少职位可用,如果职位数量大于或等于2,则返回true

{
  "query": {
    "bool": {
      "must": {
        "script": {
          "script": "def str = doc.price.value.toString(); def len = str.length(); def dot = str.indexOf('.'); return len - (dot+1) >= 2"
        }
      }
    }
  }
}

执行此操作时会出现什么错误?请显示您的映射和正在尝试的查询,但该查询不会产生您所期望的结果。@Val编辑了带有映射和queryid的post帮助?你需要更多的信息吗?