栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

elastic search 数组

elastic search 数组

Arrays | Elasticsearch Guide [7.6] | Elastic

elastic 本身是支持数组的,但是没有特定的数组类型来支持, 下面我举例数组的使用.官方文档见链接Arrays | Elasticsearch Guide [7.6] | Elastic

1. 创建一个测试index: test_array

{
    "mappings": {
        "properties": {
            "location": {
                "type": "keyword"
            }
        }
    }
}

 

2. 填入3条数据

 {"location": ["山东","北京","天津","河南","云南"]}
 {"location": ["山东", "四川","草原"]}
 {"location": ["草原"]}

 3. 验证

     a. 查询包含北京或者包含草原的

{
    "query": {
        "bool": {
            "should": [
                {
                    "term": {
                        "location": "草原"
                    }
                },
                {
                    "term": {
                        "location": "北京"
                    }
                }
            ]
        }
    }
}

返回3条数据: 

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 3,
            "relation": "eq"
        },
        "max_score": 1.5956267,
        "hits": [
            {
                "_index": "test_array",
                "_type": "_doc",
                "_id": "OnuMI34BK32v-9MebjV2",
                "_score": 1.5956267,
                "_source": {
                    "location": [
                        "山东",
                        "北京",
                        "天津",
                        "河南",
                        "云南"
                    ]
                }
            },
            {
                "_index": "test_array",
                "_type": "_doc",
                "_id": "O3uNI34BK32v-9MeIDVl",
                "_score": 0.9186288,
                "_source": {
                    "location": [
                        "山东",
                        "四川",
                        "草原"
                    ]
                }
            },
            {
                "_index": "test_array",
                "_type": "_doc",
                "_id": "PHuwI34BK32v-9MeJjVA",
                "_score": 0.9186288,
                "_source": {
                    "location": [
                        "草原"
                    ]
                }
            }
        ]
    }
}

  b. 验证既包含山东又包含北京的数据

{
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "location": "山东"
                    }
                },
                {
                    "term": {
                        "location": "北京"
                    }
                }
            ]
        }
    }
}

返回结果1条数据

{
    "took": 6,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": 2.5142555,
        "hits": [
            {
                "_index": "test_array",
                "_type": "_doc",
                "_id": "OnuMI34BK32v-9MebjV2",
                "_score": 2.5142555,
                "_source": {
                    "location": [
                        "山东",
                        "北京",
                        "天津",
                        "河南",
                        "云南"
                    ]
                }
            }
        ]
    }
}

 

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/696040.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号