我遇到的情况是,如果存在实体,则该实体会给出目录大小,否则会给出一个字符串,说明“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/