Elasticsearch基本语法和数据同步

es head插件

git clone https://github.com/mobz/elasticsearch-head.git
npm install
npm run start

ELK 启动

e:

E:\WWW\elasticsearch-6.2.3\bin

elasticsearch.bat

E:\WWW\elasticsearch-6.2.3\elasticsearch-head

npm run start

E:\WWW\kibana-6.2.3-windows-x86_64\kibana-6.2.3-windows-x86_64\bin
kibana.bat

E:\WWW\filebeat-6.2.3-windows-x86_64
filebeat.exe -e -c filebeat.yml

E:\WWW\logstash-6.2.3\bin

bin\logstash.bat -f config\mysql.yml

logstash 增量 全量同步mysql到es

input {
  jdbc {
    jdbc_driver_library => "E:\\WWW\\logstash-6.2.3\\mysql-connector-java-5.1.47.jar"
    jdbc_driver_class => "com.mysql.jdbc.Driver"
    jdbc_connection_string => "jdbc:mysql://127.0.0.1:3306/xbp_pro?useUnicode=true&characterEncoding=utf-8&useSSL=false"
    jdbc_user => "root"
	
    jdbc_password => "root"
	clean_run => true
    schedule => "* * * * *"
	
    statement => "SELECT * FROM ad_audit_user WHERE utime > :sql_last_value AND utime < NOW() ORDER BY utime desc"
  }
}
output {
  elasticsearch {
    hosts => ["127.0.0.1:9200"]
    index => "ad_audit_user"
    document_id => "%{id}"
  }
}

es 查询语句练习

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

{
  "publish_date": "2010-9-8",
  "author": "张三",
  "title": "菜谱",
  "word_count": 80
}

{
  "query": {
    "match_all": {}
  },
  "from": 1,
  "size": 1
}
{
  "query": {
    "match_all": {}
  }
}

{
  "query": {
    "match": {
      "title": "elasticsearch"
    }
  },
  "sort": {
    "publish_date": {
      "order": "desc"
    }
  }
}

聚合查询
{
  "query": {
    "match_phrase": {
      "title": "elasticsearch高阶"
    }
  },
  "sort": {
    "publish_date": {
      "order": "desc"
    }
  }
}

{
  "query": {
    "multi_match": {
      "query": "张三",
      "fields": [
        "author",
        "title"
      ]
    }
  }
}

{
  "query": {
    "query_string": {
      "query": "(张三 AND 菜谱) OR 九阳神功",
      "fields": [
        "title",
        "aurhor"
      ]
    }
  }
}
http://localhost:9200/book/_search	
{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "word_count": 80
        }
      }
    }
  }
}
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "title": "elasticsearch"
          }
        },
        {
          "match": {
            "author": "李四"
          }
        }
      ]
    }
  }
}
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "title": "elasticsearch"
          }
        },
        {
          "match": {
            "author": "李四"
          }
        }
      ]
    }
  }
}

{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "title": "elasticsearch"
        }
      }
    }
  }
}

match 模糊匹配  
match_phrase 完全匹配
multi_match  多字段匹配
filter 过滤两种
(query filter )
字段匹配
{
  "query": {
    "term": {
      "author": "张三"
    }
  }
}
范围匹配
{
  "query": {
    "range": {
      "word_count": {
        "gte": 70,
        "lte": 200
      }
    }
  }
}
GET _search
{
  "query": {
    "match_all": {}
  }
}
POST _analyze
{
  "analyzer":"standard",
  "text": "我是中国人"
}
POST _analyze
{
  "analyzer":"ik_smart",
  "text": "我是中国人"
}

POST _analyze
{
  "analyzer":"ik_max_word",
  "text": "我是中国人"
}
GET _cat/indices
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值