zoukankan      html  css  js  c++  java
  • ElasticSearch高级查询

    ElasticSearch高级查询

    https://www.imooc.com/video/15759/0
    
    ElasticSearch查询
    
    
    
    
    
    1,子条件查询:特定字段查询所指特定值
    
    1.1query context,有_score
    1.1.1全文本查询,针对文本类型数据
    1.1.1.1 模糊匹配
    POST http://127.0.0.1/book/_search
    {
        "query":{
            "match":{
                "author":"瓦力"
            }
        }
    }
    {
        "query":{
            "match":{
                "title":"ElasticSearch入门"
            }
        }
    }
    
    
    1.1.1.2 习语匹配
    {
        "query":{
            "match_phrase":{
                "title":"ElasticSearch入门"
            }
        }
    }
    
    1.1.1.3 多字段匹配
    {
        "query":{
            "multi_match":{
                "query":"瓦力",
                "fields":["author","title"]
            }
        }
    }
    
    1.1.1.4 语法查询
    {
        "query":{
            "query_string":{
                "query":"ElasticSearch AND 大法"
            }
        }
    }
    
    {
        "query":{
            "query_string":{
                "query":"(ElasticSearch AND 大法) OR Python"
            }
        }
    }
    
    {
        "query":{
            "query_string":{
                "query":"瓦力 OR ElasticSearch",
                "fields":["title","author"]
            }
        }
    }
    1.1.2字段级别查询,针对结构化数据,如数字、日期等
    
    {
        "query":{
            "term":{
                "word_count":1000
            }
        }
    }
    
    {
        "query":{
            "term":{
                "author":"瓦力"
            }
        }
    }
    {
        "query":{
            "range":{
                "word_count":{
                    "gte":1000,
                    "lte":2000
                }
            }
        }
    }
    {
        "query":{
            "range":{
                "word_count":{
                    "gt":1000,
                    "lte":2000
                }
            }
        }
    }
    {
        "query":{
            "range":{
                "publish_date":{
                    "gte":"2017-01-01",
                    "lte":"2017-12-31"
                }
            }
        }
    }
    {
        "query":{
            "range":{
                "publish_date":{
                    "gte":"2017-01-01",
                    "lte":"now"
                }
            }
        }
    }
    1.2filter context
    filter表示查找是不是
    
    {
        "query": {
            "bool": {
                "filter": {
                    "term": {
                        "word_count": 1000
                    }
                }
            }
        }
    }
    
    
    
    2,复合条件查询:以一定的逻辑组合子条件查询
    
    
    2.1 固定分数查询
    {
        "query": {
            "match": {
                "title": "ElasticSearch"
            }
        }
    }
    
    {
        "query": {
            "constant_score": {
                "filter": {
                    "match": {
                        "title": "ElasticSearch"
                    }
                }
            }
        }
    }
    
    {
        "query": {
            "constant_score": {
                "filter": {
                    "match": {
                        "title": "ElasticSearch"
                    }
                },
                "boost": 2
            }
        }
    }
    
    2.2 bool查询
    
    should - 表示 或者
    {
        "query": {
            "bool": { 
                "should": [
                    {
                        "match":{
                            "author": "瓦力"
                        }
                    },
                    {
                        "match": {
                            "title": "ElasticSearch"
                        }
                        
                    }
                    
                ]
            }
        }
    }
    
    must - 表示 必须
    
    {
        "query": {
            "bool": { 
                "must": [
                    {
                        "match":{
                            "author": "瓦力"
                        }
                    },
                    {
                        "match": {
                            "title": "ElasticSearch"
                        }
                        
                    }
                    
                ]
            }
        }
    }
    
    {
        "query": {
            "bool": { 
                "must": [
                    {
                        "match":{
                            "author": "瓦力"
                        }
                    },
                    {
                        "match": {
                            "title": "ElasticSearch"
                        }
                        
                    }
                    
                ],
                "filter": [
                    {
                        "term": {
                            "word_count": 1000
                        }
                    }
                ]
            }
        }
    }
    {
        "query": {
            "bool": { 
                "must_not": {
                    "term": {
                        "author": "瓦力"
                    }
                }
            }
        }
    }

    https://www.imooc.com/video/15759/0
    ElasticSearch查询




    1,子条件查询:特定字段查询所指特定值
    1.1query context,有_score1.1.1全文本查询,针对文本类型数据1.1.1.1 模糊匹配POST http://127.0.0.1/book/_search{    "query":{        "match":{            "author":"瓦力"        }    }}{    "query":{        "match":{            "title":"ElasticSearch入门"        }    }}

    1.1.1.2 习语匹配{    "query":{        "match_phrase":{            "title":"ElasticSearch入门"        }    }}
    1.1.1.3 多字段匹配{    "query":{        "multi_match":{            "query":"瓦力",            "fields":["author","title"]        }    }}
    1.1.1.4 语法查询{    "query":{        "query_string":{            "query":"ElasticSearch AND 大法"        }    }}
    {    "query":{        "query_string":{            "query":"(ElasticSearch AND 大法) OR Python"        }    }}
    {    "query":{        "query_string":{            "query":"瓦力 OR ElasticSearch",            "fields":["title","author"]        }    }}1.1.2字段级别查询,针对结构化数据,如数字、日期等
    {    "query":{        "term":{            "word_count":1000        }    }}
    {    "query":{        "term":{            "author":"瓦力"        }    }}{    "query":{        "range":{            "word_count":{                "gte":1000,                "lte":2000            }        }    }}{    "query":{        "range":{            "word_count":{                "gt":1000,                "lte":2000            }        }    }}{    "query":{        "range":{            "publish_date":{                "gte":"2017-01-01",                "lte":"2017-12-31"            }        }    }}{    "query":{        "range":{            "publish_date":{                "gte":"2017-01-01",                "lte":"now"            }        }    }}1.2filter contextfilter表示查找是不是
    {"query": {"bool": {"filter": {"term": {"word_count": 1000}}}}}


    2,复合条件查询:以一定的逻辑组合子条件查询

    2.1 固定分数查询{"query": {"match": {"title": "ElasticSearch"}}}
    {"query": {"constant_score": {"filter": {"match": {"title": "ElasticSearch"}}}}}
    {"query": {"constant_score": {"filter": {"match": {"title": "ElasticSearch"}},"boost": 2}}}
    2.2 bool查询
    should - 表示 或者{"query": {"bool": { "should": [{"match":{"author": "瓦力"}},{"match": {"title": "ElasticSearch"}}]}}}
    must - 表示 必须
    {"query": {"bool": { "must": [{"match":{"author": "瓦力"}},{"match": {"title": "ElasticSearch"}}]}}}
    {"query": {"bool": { "must": [{"match":{"author": "瓦力"}},{"match": {"title": "ElasticSearch"}}],"filter": [{"term": {"word_count": 1000}}]}}}{"query": {"bool": { "must_not": {"term": {"author": "瓦力"}}}}}

  • 相关阅读:
    [python]CompressionError: bz2 module is not available
    [App Store Connect帮助]四、添加 App 图标、App 预览和屏幕快照(2)添加一个 App Store 图标
    [App Store Connect帮助]四、添加 App 图标、App 预览和屏幕快照(1)App Store 图标、App 预览和屏幕快照概述
    [App Store Connect帮助]三、管理 App 和版本(8)编辑 App 的用户访问权限
    [App Store Connect帮助]三、管理 App 和版本(7)移除 App
    [App Store Connect帮助]三、管理 App 和版本(6.3)转让 App:接受 App 转让
    [App Store Connect帮助]三、管理 App 和版本(6.3)转让 App:发起 App 转让
    [App Store Connect帮助]三、管理 App 和版本(6.2)转让 App:App 转让条件
    [App Store Connect帮助]三、管理 App 和版本(6.1)转让 App:App 转让概述
    [App Store Connect帮助]三、管理 App 和版本(5)添加平台以创建通用购买
  • 原文地址:https://www.cnblogs.com/stono/p/9060433.html
Copyright © 2011-2022 走看看