【JSON123】JSONPath

公司业务复杂度导致存储在ES Index Cache上的JSON数据深度嵌套。

使用DQSL查询语句无法快速准确的找到深层key-value元素。

JavaScript Object Notation, or JSON

1. ElasticSearch的QDSL(Query Domain Search Language)查询

https://www.elastic.co/guide/en/elasticsearch/guide/master/index.html

https://www.jianshu.com/p/0a0d711030f3

举例:搜索所有newType字段为1的数据:
GET mei_toutiao/_search
{
    "query" : {
        "constant_score" : {
            "filter" : {
                "bool" : {
                    "must" : {
                        "term" : {
                            "newType": "1"
                        }
                    }
                }
            }
        }
    }
}
12345678910111213141516
搜索所有newType字段不为1的数据:
GET mei_toutiao/_search
{
    "query" : {
        "constant_score" : {
            "filter" : {
                "bool" : {
                    "must_not" : {
                        "term" : {
                            "newType": "1"
                        }
                    }
                }
            }
        }
    }
}
12345678910111213141516
注意:
GET mei_toutiao/_search
{
    "query" : {
        "constant_score" : {
            "filter" : {
                "bool" : {
                    "must" : {
                        "match_phrase" : {
                            "userId": "1C210E82-21B7-4220-B267-ED3DA6635F6F"
                        }
                    }
                }
            }
        }
    }
}
12345678910111213141516
上面可以查到相应的数据,而下面却不行
GET mei_toutiao/_search
{
    "query" : {
        "constant_score" : {
            "filter" : {
                "bool" : {
                    "must" : {
                        "term" : {
                            "userId": "1C210E82-21B7-4220-B267-ED3DA6635F6F"
                        }
                    }
                }
            }
        }
    }
}
---------------------
作者:小强签名设计
来源:CSDN
原文:https://blog.csdn.net/m0_37739193/article/details/82388229
版权声明:本文为博主原创文章,转载请附上博文链接!

2. 了解下JSONPath,定位查询。

https://www.cnblogs.com/angle6-liu/p/10580792.html

JSONPath语法元素与XPath对应的完整概述和并排比较。

XpathJSONPath描述
/ $ 跟节点
. @ 现行节点
/ . or [] 取子节点
.. n/a 就是不管位置,选择所有符合条件的条件
* * 匹配所有元素节点
[] [] 迭代器标示(可以在里面做简单的迭代操作,如数组下标,根据内容选值等)
&#124 [,] 支持迭代器中做多选
[] ?() 支持过滤操作
n/a () 支持表达式计算
() n/a 分组,JsonPath不支持

 举例:https://blog.csdn.net/lwg_1540652358/article/details/84111339

3. 因为查找遇到困难,引申出来JSON数据定义时,数据存储为对象or数组的问题。

JSON有三类元素: 

1、结构体(关键字:大括号)
2、键值对(关键字:冒号)
3、数组(关键字:中括号)

组织规则:
结构体中放一个或者多个键值对。
键只能是字符串。
值可以是:字符串、数字、null、true、false、结构体或者数组。
数组中存放一个或者多个值。

https://www.v2ex.com/t/507056

https://www.jianshu.com/p/fa2b28998adf

https://blog.csdn.net/weixin_30069221/article/details/85109746

https://blog.csdn.net/weixin_41604225/article/details/85060923

https://social.microsoft.com/Forums/zh-CN/da99b2c1-8f74-487b-a8ff-4b25a06144ac/keyjson?forum=295

相同key的多个对象,属于非法JSON!!!

偶遇一个APIJSON库,有空学习了解下

http://apijson.org/

原文地址:https://www.cnblogs.com/cathygx/p/11178896.html