elasticsearch - Elasticsearch匹配精确的浮点值

标签 elasticsearch

我想为过滤器中的浮点数匹配精确值。在此过滤器中考虑myfloat:

{
  "filter" : { "bool" : { "must" : [
    { "match" : { "thing1" : "ABC" } },
    { "match" : { "thing2" : "SOMECODE" } },
    { "match" : { "myfloat" : 6490.1 } }
  ] } },
  "weight" : 10
}

但是,似乎忽略了小数点后的所有内容。换句话说,myfloat为6490.5的记录将匹配。

有没有办法让它仅在完全匹配时才匹配?这些是美元值,因此不要超过两个小数。

编辑:

ES所说的是数据类型:
"myfloat" : {
    "type" : "long"
},

最佳答案

您应该使用“term”进行完全匹配(https://www.elastic.co/guide/en/elasticsearch/reference/2.0/query-dsl-term-query.html)
所以你的过滤器将成为

{
  "filter" : { "bool" : { "must" : [
    { "match" : { "thing1" : "ABC" } },
    { "match" : { "thing2" : "SOMECODE" } },
    { "term" : { "myfloat" : 6490.1 } }
  ] } },
  "weight" : 10
}

关于elasticsearch - Elasticsearch匹配精确的浮点值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38754065/

相关文章:

elasticsearch - 基于多个字段的Kibana可视化

elasticsearch - 如何结合 Neo4j UUID 和 Neo4j Elastic Search 插件

elasticsearch - 在ElasticSearch 7.5中多样化搜索结果

elasticsearch - 如何结合multi_match和两个 bool 过滤器

elasticsearch - SUM聚合将每个值取整?

elasticsearch - 如何使用NEST在Elasticsearch中按索引获取所有文档?

php - Elasticsearch 1.4和Drupal 7:在查询中使用数组

c# - Elasticsearch 来自数组的多个聚合

python - 带有Python请求的Elasticsearch:msearch请求必须以换行符终止

search - 使用Elasticsearch在子文档中搜索术语