Elasticsearch terms查询

terms 查询

terms 查询与 term 查询一样,但它允许你指定多值进行匹配,如果这个字段包含了指定值中的任何一个值,那么这个文档满足条件。

# 新增文档
PUT /ad/_doc/5
{
    "name":"Vivo",
    "price":2999,
    "color":"blue",
    "ad":"this is a blue phone",
    "label":[
        "blue",
        "Vivo"
    ]
}

# 查询ad字段包含red或者blue值的文档
GET /ad/_search
{
    "query":{
        "terms":{
            "ad":[
                "red",
                "blue"
            ]
        }
    }
}

# 输出结果
{
    "took":29,
    "timed_out":false,
    "_shards":{
        "total":1,
        "successful":1,
        "skipped":0,
        "failed":0
    },
    "hits":{
        "total":{
            "value":2,
            "relation":"eq"
        },
        "max_score":1,
        "hits":[
            {
                "_index":"ad",
                "_type":"_doc",
                "_id":"2",
                "_score":1,
                "_source":{
                    "name":"xiaomi 8",
                    "price":4000,
                    "color":"red",
                    "ad":"this is a red phone",
                    "label":[
                        "white",
                        "xiaomi"
                    ]
                }
            },
            {
                "_index":"ad",
                "_type":"_doc",
                "_id":"5",
                "_score":1,
                "_source":{
                    "name":"Vivo",
                    "price":2999,
                    "color":"blue",
                    "ad":"this is a blue phone",
                    "label":[
                        "blue",
                        "Vivo"
                    ]
                }
            }
        ]
    }
}
展开阅读全文

页面更新:2024-02-14

标签:字段   条件   文档

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top