zoukankan      html  css  js  c++  java
  • elasticsearch

    https://www.elastic.co/

    https://www.elastic.co/cn/downloads

    --head插件的使用

    https://github.com/ ==>  

    mobz/elasticsearch-head

     

    --分布式安装

    --基础概念

     

    {
        "settings": {
            "number_of_shards": 3,
            "number_of_replicas": 1
        },
        "mappings": {
            "man": {
                "properties": {
                    "name": {
                        "type": "text"
                    },
                    "country": {
                        "type": "keyword"
                    },
                    "age": {
                        "type": "integer"
                    },
                    "date": {
                        "type": "date",
                        "format": "yyyy-MM-dd HH:mm:ss|| yyyy-MM-dd||epoch_millis"
                    }
                }
            },
            "woman": {
                
            }
        }
    }

    put

    ip:端口/索引/类型/id

    {
        "name": "tom",
        "country": "US",
        "age": 30,
        "date": "1987-05-05"
    }

    注: post方式, 自动生成id, 无序指定id值

    post

    ip:端口/索引/类型/id/_update

    {
        "doc": {
            "name": "haah"
        }
    }
    {
        "script": {
            "lang": "painless",
            "inline": "ctx._source.age += 10"
        }
    }
    {
        "script": {
            "lang": "painless",
            "inline": "ctx._source.age = parmas.age",
            "parmas": {
                "age": 100
            }
        }
    }

    注: delete方式

    --基本查询

    {
        "settings": {
            "number_of_shards": 3,
            "number_of_replicas": 1
        },
        "mappings": {
            "novel": {
                "properties": {
                    "word_count": {
                        "type": "integer"
                    },
                    "author": {
                        "type": "keyword"
                    },
                    "title": {
                        "type": "text"
                    },
                    "publish_date": {
                        "type": "date",
                        "format": "yyyy-MM-dd HH:mm:ss|| yyyy-MM-dd||epoch_millis"
                    }
                }
            }
        }
    }

    get:

    post: ip:端口/索引/类型/_search

    {
        "query": {
            "match_all": {}
        }
    }
    {
        "query": {
            "match_all": {}
        },
        "from": 1,
        "size": 2
    }
    {
        "query": {
            "match_all": {
                "title": "ElasticSearch"
            }
        },
        "sort": [
            {"publish_date": {"order": "desc"}}    
        ]
    }
    {
        "aggs": {
            "group_by_word_count": {
                "terms": {
                    "field": "word_count"
                }
            }
        }
    }
    {
        "aggs": {
            "group_by_word_count": {
                "terms": {
                    "field": "word_count"
                }
            },
            "group_by_publish_date": {
                "terms": {
                    "field": "publish_date"
                }
            }
        }
    }
    {
        "aggs": {
            "group_by_word_count": {
                "stats": {
                    "field": "word_count"
                }
            }
        }
    }
    {
        "aggs": {
            "group_by_word_count": {
                "min": {
                    "field": "word_count"
                }
            }
        }
    }

    --高级查询

    1全文本

    模糊匹配
    {
    "query": { "match": { "title": "ElasticSearch入门" } } }
    整个
    { "query": { "match_phrase": { "title": "ElasticSearch入门" } } }
    
    
    多字段

    {
    "query": { "multi_match": { "query": "haah", "fields": ["author", "title"] } } }
    语法查询
    {
    "query": { "query_string": { "query": "ElasticSearch AND 大发", } } }
    {
        "query": {
            "query_string": {
                "query": "(ElasticSearch AND 大发) OR Pythonh",
            }
        }
    }
    {
        "query": {
            "query_string": {
                "query": "ElasticSearch OR haha",
                "fields": ["title", "author"]
            }
        }
    }

    2字段查询(结构化的查询)

    {
        "query": {
            "term": {
                "word_count": 1000
            }
        }
    }
    {
        "query": {
            "term": {
                "author": "haha"
            }
        }
    }
    范围
    {
    "query": { "range": { "word_count": { "gte": 1000, "lte": 2000 } } } }
    {
        "query": {
            "range": {
                "publish_date": {
                    "gt": "2017-01-01",
                    "lte": "2017-12-31"
                }
            }
        }
    }
    {
        "query": {
            "range": {
                "publish_date": {
                    "gt": "2017-01-01",
                    "lte": "now"
                }
            }
        }
    }

    {
        "query": {
            "bool": {
                "filter": {
                    "term": {
                        "word_count": 1000
                    }
                }
            }
        }
    }

    1固定分数查询

    {
        "query": {
            "constant_score": {
                "filter": {
                    "match": {
                        "title": "ElasticSearch入门"
                    }
                }
            }
        }
    }
    {
        "query": {
            "constant_score": {
                "filter": {
                    "match": {
                        "title": "ElasticSearch入门"
                    }
                },
                "boost": 2
            }
        }
    }

    2布尔查询

    {
        "query": {
            "bool": {
                "should": [
                    {
                        "match": {
                            "author": "haha"
                        }
                    },
                    {
                        "match": {
                            "title": "ElasticSearch"
                        }
                    }
                ]
            }
        }
    }
    {
        "query": {
            "bool": {
                "must": [
                    {
                        "match": {
                            "author": "haha"
                        }
                    },
                    {
                        "match": {
                            "title": "ElasticSearch"
                        }
                    }
                ]
            }
        }
    }
    {
        "query": {
            "bool": {
                "must": [
                    {
                        "match": {
                            "author": "haha"
                        }
                    },
                    {
                        "match": {
                            "title": "ElasticSearch"
                        }
                    }
                ]
            },
            "filter": [
                {
                    "term": {
                        "word_count": 1000
                    }
                }
            ]
        }
    }
    {
        "query": {
            "bool": {
                "must_not": {
                    "term": {
                        "author": "haah"
                    }
                }
            }
        }
    }

    spring boot 集成 es

  • 相关阅读:
    构建maven的web项目时注意的问题(出现Error configuring application listener of class org.springframework.web.context.ContextLoaderListener 或者前端控制器无法加载)
    c3p0私有属性checkoutTimeout设置成1000引发的调试错误:
    sql面试题(学生表_课程表_成绩表_教师表)
    传值与传址
    new String()理解
    hashcode的理解
    CentOs安装ssh服务
    openstack swift memcached
    openstack swift middleware开发
    java实现二叉树
  • 原文地址:https://www.cnblogs.com/liuzhipeng/p/7565412.html
Copyright © 2011-2022 走看看