【发布时间】:2015-07-15 03:55:16
【问题描述】:
我有一个案例,我在键值对 json 格式的文档中收集了一些常规信息和数据库信息(db2、oracle、sybase、informix)。
我还有一些规则来检查上述文档是否满足特定规则,如果满足,则返回该特定文档进行分析。
这是文档
PUT /twitter/tweet/1
{
"name": "Athena",
"version": 1,
"db": {
"@type": "Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 64bit",
"oracle_props": [
{
"@name": "open_cursors",
"@value": 4000
},
{
"@name": "USER_ROLE_PRIVS_COUNT",
"@value": 1
}
]
}
}
这就是它的映射
PUT /twitter/tweet/_mapping
{
"properties": {
"db": {
"type": "object",
"properties": {
"@type": {
"type": "string"
},
"oracle_props": {
"type": "nested",
"properties": {
"@name": {
"type": "string"
},
"@value": {
"type": "long"
}
}
}
}
}
}
}
规则标准
列出带有name Athena 和Oracle database 的推文具有opencursors less than recommendaed value 4000 或opencursors is not present 时的文档。
所以上面的文档/twitter/tweet/1只有在以下匹配时才会返回。
- If (name == "Athena") && (db.@type contains "Oracle" 关键字)
- 和(如果((“open_cursors”@value
下面是匹配上述文档但缺少最后一个条件的搜索查询(即使在“db.oracle_props.@name”下缺少“open_cursors”键时也显示文档“/twitter/tweet/1”)
GET /twitter/tweet/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"tweet.name": "Athena"
}
},
{
"match": {
"tweet.db.@type": "Oracle"
}
}
],
"should": [
{
"nested": {
"path": "db.oracle_props",
"query": {
"bool": {
"must": [
{
"term": {
"db.oracle_props.@name": "open_cursors"
}
},
{
"range": {
"db.oracle_props.@value": {
"lt": 4001
}
}
}
]
}
}
}
}
],
"minimum_should_match": 1
}
}
}
【问题讨论】:
标签: json elasticsearch