elasticsearch - 如何检查数字范围以及Elasticsearch中的字符串值?

标签 elasticsearch

我遇到的情况是,如果存在实体,则该实体会给出目录大小,否则会给出一个字符串,说明“IATEMPDIR不存在”。

有没有什么方法可以识别实体client.tempsize lt 65594 && client.tempsize值是否不是字符串(因此,当它具有IATEMPDIR does not exist值时,它也应该返回此查询)。在这种情况下,如何检查数字范围(如果是字符串)?

我正在使用渗滤剂

PUT /eg/.percolator/1
{   
    "sort": {
        "rule.step": { "order": "asc" }
    },
    "query": {
        "filtered": {
           "query": {
               "bool": {
                   "must": [
                      {
                          "match": {
                             "client.name": "Athena"
                          }
                      },
                      {
                          "range": {
                             "client.tempsize": {
                                    "lt": 65594
                             }
                          }
                      }
                    ]                   
               }               
           }
        }
    },
    "rule": {
        "ruledesc": "Client should be Athena & tempsize should have sufficient space (eg: > 65594) and should not be a string",
        "step": 1
    }    
}

我的文档
GET /eg/message/_percolate
{
    "doc": {
        "client": {
            "name": "Athena",
            "tempsize": "IATEMPDIR does not exist"
        }
    }
}

上面的文档给我...MapperParsingException[failed to parse [client.tempsize]]; nested: NumberFormatException...,但是当我使用"tempsize": 12时,它会返回正确的结果。
{
   "took": 3,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "total": 1,
   "matches": [
      {
         "_index": "eg",
         "_id": "1"
      }
   ]
}

更新

经过 ppearcy 的回答后。我将映射更改为
PUT /eg/message/_mapping
{
   "properties": {
      "client": {
         "properties": {
            "name": {
               "type": "string"
            },
            "tempsize": {
               "type": "long",
               "ignore_malformed" : "true"
            }
         }
      }
   }
}

并且下面的文档不会导致我的查询,并且忽略了字符串
GET /eg/message/_percolate
{
    "doc": {
        "client": {
            "name": "Athena",
            "tempsize": "IATEMPDIR does not exist"
        }
    }
}

因此,如果我给"tempsize": "65594",那是否考虑双引号内的数字(因为给小于65594的数字会返回我的查询)?还是会在某个地方破裂?

最佳答案

您应该在字段映射中设置“ignore_malformed”:“true”。

这将允许您仍然为文档编制索引,并且非数字将被忽略并且可以使用缺少/存在的查询类型进行查询。

使用lucene查询语法进行简化,最终查询将类似于:

_missing_:client.tempsize OR client.tempsize:[0 TO 65594]

在此处查看数字部分以获取更多信息:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html

关于elasticsearch - 如何检查数字范围以及Elasticsearch中的字符串值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24610396/

相关文章:

elasticsearch - 删除 ElasticSearch 2.x 中某种类型的所有文档

elasticsearch - Elasticsearch :与带有过滤器的最大值有关的值

Elasticsearch 丢弃了太多请求——缓冲区会改善情况吗?

database - ElasticSearch 异步发布

elasticsearch - 将ElasticSearch和Azure搜索作为常规数据存储与搜索结合使用是否合适?

elasticsearch - Elasticsearch 查询嵌套文档数组

indexing - 通过更新索引模板来更新 Elasticsearch 映射

elasticsearch - Elasticsearch关联完全匹配项

elasticsearch - 多个索引上的ElasticSearch分页

php - Elasticsearch query_string包含未查询的术语