• Stars
    star
    189
  • Rank 204,649 (Top 5 %)
  • Language
    Java
  • License
    MIT License
  • Created almost 10 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ElasticSearch Java Rest Client Examples

jest

ElasticSearch Java Rest Client Examples

高亮查询(highlight)

POST http://127.0.0.1:9200/news/_search?q=李克强
{
    "query" : {
        match_all:{}
    },
    "highlight" : {
        "pre_tags" : ["<font color='red'>", "<b>", "<em>"],
        "post_tags" : ["</font>", "<b>", "</em>"],
        "fields" : [
            {"title" : {}},
            {"content" : {
                "fragment_size" : 350,
                "number_of_fragments" : 3,
                "no_match_size": 150
            }}
        ]
    }
}
POST http://127.0.0.1:9200/news/_search?q=李克强
{
    "query" : {
        match_all:{}
    },
    "highlight" : {
        "pre_tags" : ["<font color='red'><b><em>"],
        "post_tags" : ["</font><b></em>"],
        "fields" : [
            {"title" : {}},
            {"content" : {
                "fragment_size" : 350,
                "number_of_fragments" : 3,
                "no_match_size": 150
            }}
        ]
    }
}

删除索引

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html

DELETE http://127.0.0.1:9200/news

创建索引

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html

PUT http://127.0.0.1:9200/news

创建或修改mapping

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html

PUT /{index}/_mapping/{type}
PUT http://127.0.0.1:9200/news/_mapping/article
{
  "article": {
    "properties": {
      "pubdate": {
        "type": "date",
        "format": "dateOptionalTime"
      },
      "author": {
        "type": "string"
      },
      "content": {
        "type": "string"
      },
      "id": {
        "type": "long"
      },
      "source": {
        "type": "string"
      },
      "title": {
        "type": "string"
      },
      "url": {
        "type": "string"
      }
    }
  }
}

查看mapping

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html

GET http://127.0.0.1:9200/_all/_mapping

GET http://127.0.0.1:9200/_mapping
GET http://127.0.0.1:9200/news/_mapping/article

输出:

{
  "news": {
    "mappings": {
      "article": {
        "properties": {
          "author": {
            "type": "string"
          },
          "content": {
            "type": "string"
          },
          "id": {
            "type": "long"
          },
          "pubdate": {
            "type": "date",
            "store": true,
            "format": "yyyy-MM-dd HH:mm:ss"
          },
          "source": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "url": {
            "type": "string"
          }
        }
      }
    }
  }
}

删除mapping

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-mapping.html

[DELETE] /{index}/{type}

[DELETE] /{index}/{type}/_mapping

[DELETE] /{index}/_mapping/{type}
DELETE http://127.0.0.1:9200/news/_mapping/article

ansj分词器测试

http://127.0.0.1:9200/news/_analyze?analyzer=ansj_index&text=习近平

http://127.0.0.1:9200/news/_analyze?analyzer=ansj_index&text=我是中国人

http://127.0.0.1:9200/news/_analyze?analyzer=ansj_index&text=汪东兴同志遗体在京火化汪东兴同志病重期间和逝世后,习近平李克强张德江俞正声刘云山王岐山张高丽江泽民胡锦涛等同志,前往医院看望或通过各种形式对汪东兴同志逝世表示沉痛哀悼并向其亲属表示深切慰问新华社北京8月27日电中国共产党的优秀党员

ansj分词器查询

  • 普通查询

http://127.0.0.1:9200/news/_search?q=习近平&analyzer=ansj_index&size=50

  • 指定term查询

http://127.0.0.1:9200/news/_search?q=content:江泽民&analyzer=ansj_index&size=50

http://127.0.0.1:9200/news/_search?q=title:江泽民&analyzer=ansj_index&size=50

http://127.0.0.1:9200/news/_search?q=source:新华网&analyzer=ansj_index&size=50

  • 其中ansj_index为在elasticsearch.yml文件中配置的ansj分词器

elasticsearch rest api 快速上手

elasticsearch-jdbc

@echo off

set DIR=%~dp0
set LIB="%DIR%\..\lib\*"
set BIN="%DIR%\..\bin\*"

REM ???
echo {^
    "type" : "jdbc",^
    "jdbc" : {^
        "url" : "jdbc:mysql://localhost:3306/news",^
        "user" : "root",^
        "password" : "root",^
        "schedule" : "0 0/15 * ? * *",^
        "sql" :  [^
             {"statement":"SELECT title,content,url,source,author,pubdate FROM news"},^
             {^
                "statement":"SELECT title,content,url,source,author,pubdate FROM news where pubdate > ?",^
                "parameter" : [ "$metrics.lastexecutionstart" ]^
             }^
	],^
	"autocommit" : true,^
        "treat_binary_as_string" : true,^
        "elasticsearch" : {^
             "cluster" : "elasticsearch",^
             "host" : "localhost",^
             "port" : 9300^
        },^
        "index" : "news",^
        "type" : "article"^
      }^
}^ | "%JAVA_HOME%\bin\java" -cp "%LIB%" -Dlog4j.configurationFile="file://%DIR%\log4j2.xml" "org.xbib.tools.Runner" "org.xbib.tools.JDBCImporter"

elasticsearch-jdbc 插件的使用

More Repositories

1

awesome-ios-animation

A curated list of awesome iOS animation, including Objective-C and Swift libraries
5,134
star
2

awesome-ios-chart

A curated list of awesome iOS chart libraries, including Objective-C and Swift
1,526
star
3

notes

notes
Shell
1,513
star
4

ELK

搭建ELK日志分析平台。
775
star
5

oltu-oauth2-example

使用Apache Oltu 搭建Oauth2 Server及Client开放授权
Java
339
star
6

spring-quartz-cluster-sample

Spring整合Quartz基于数据库的分布式定时任务,可动态添加、删除、修改定时任务。
Java
313
star
7

vagrant-kubernetes-cluster

Vagrant一键安装Kubernetes集群。安装 Metrics Server 、Kuboard 、Kubernetes Dashboard、KubePi、Kubernetes集群监控prometheus-operator
Shell
284
star
8

maven-framework-project

基于maven的多框架和多视图融合技术(Struts1、Struts2、Spring、SpringMVC、Hibernate、Ibatis、MyBatis、Spring Data JPA、DWR)
Java
212
star
9

FoodPin

用Swift写的一个简单的App
Swift
199
star
10

Swift-PM25

一个基于Swift实现的PM2.5查询示例
Swift
137
star
11

cas-server-webapp

CAS Server 4.0二次开发。添加登录错误三次及以上验证码校验、用户登录数据库认证、CAS Server REST等
Java
123
star
12

shiro-jwt-springboot

shiro整合jwt前后端分离权限认证示例
Java
104
star
13

cas-sso-samples

CAS单点登录案例。整合了CAS OAuth2、Apache Shiro、Spring Security等
HTML
66
star
14

spring-activiti-webapp

Spring整合Activiti的简单例子
Java
59
star
15

NotifyQQ

基于Mojo-WebQQ的Jenkins构建后QQ提醒插件
Java
57
star
16

activiti-demo

一个基于Activiti5.13和Bootstrap3.0.3的请假流程
Java
56
star
17

elasticsearch

elasticsearch中文版,基于elasticsearch-1.7.1。集成常用的各种插件,不定期更新
JavaScript
55
star
18

cloud

云计算之hadoop、hive、hue、oozie、sqoop、hbase、zookeeper环境搭建及配置文件
Shell
51
star
19

sharding-jdbc-sample

基于当当Sharding-JDBC数据库分库分表访问示例程序
Java
46
star
20

GolangStudy

用Swift写的Golang学习App
Swift
45
star
21

springboot-dubbox-simple

Dubbox整合Spring Boot基于Avro、Thrift协议构建REST服务
Java
40
star
22

spring-boot-oauth2-example

Java
32
star
23

dubbo-example

dubbo example
Java
25
star
24

spring-boot-apollo-sample

Demo project for Spring Boot Apollo
Java
22
star
25

WebIM

JavaScript/jQuery、HTML、CSS 构建 Web IM 远程及时聊天通信程序
JavaScript
20
star
26

bing-wallpaper

Java
20
star
27

mybatis-spring

MyBatis整合Spring并使用log4jdbc或者p6spy输出真实的sql语句
Java
17
star
28

tomcat7-nginx-redis-memcached-cluster

使用Redis或Memcached实现Tomcat7+Nginx集群及Session共享
Nginx
17
star
29

FullCalendar

基于FullCalendar二次开发,支持农历功能。中文测试OK
JavaScript
15
star
30

distributed-lock-examples

史上最全的分布式锁案例合辑。我们不造轮子,只需用好轮子!
Java
14
star
31

kafka-log4j

使用kafka实现log4j日志集中管理
Java
13
star
32

graphql-example

graphql spring boot example
Java
11
star
33

springboot-weixin-mp

SpringBoot整合weixin-java-tools实现微信公众号登录授权
Java
11
star
34

docker-hub

Shell
11
star
35

mina-examples

一个简单的spring整合mina实例
Java
11
star
36

programminghive

Programming Hive读书笔记
11
star
37

MovieSite

Mahout入门实例-基于 Apache Mahout 构建社会化推荐引擎-实战(参考IBM)
Java
10
star
38

hibernate-search-example

hibernate search example(分别使用hibernate、jpa两种方式实现,使用IKAnalyzer、paoding两种分词器实现中文分词)
Java
10
star
39

spring-data-elasticsearch-example

Spring Data Elasticsearch Example
Java
9
star
40

storm-example

a storm kafka examples
Java
9
star
41

apache2-tomcat7-cluster

Apache、Tomcat7集群session共享及负载均衡
ApacheConf
8
star
42

SpringQuartzClusterSample

Spring Quartz分布式集群配置
Java
8
star
43

activemq-example

ActiveMQ Spring Jms Example
Java
8
star
44

cas-oauth-example-3.5.x

cas通用公共组件,基于数据库和oauth认证。
Java
7
star
45

swagger-springmvc-example

使用Swagger构建SpringMVC REST服务API文档
JavaScript
7
star
46

springcloud-zookeeper-example

Java
7
star
47

solr-ik-database

solr3.6.1整合tomcat及中文分词,并索引mysql数据库实现搜索功能
Shell
6
star
48

zipkin-server-example

Java
6
star
49

resteasy-restfull-examples

基于resteasy的restfull api接口示例
Java
6
star
50

weibo-trending-hot-search

Python
6
star
51

spring-log4j-activemq

将log4j日志输出到activemq
Java
6
star
52

javaagent-samples

java instrument samples
Java
6
star
53

k8s-example

Spring Boot整合Kubernetes
Java
5
star
54

mybatis-generator-example

mybatis-generator-example
Java
5
star
55

52pojie_sign_bot

Python
5
star
56

k3s-istio-lab

搭建k3s集群和istio环境
Shell
5
star
57

Nutch1.0

Nutch1.0修改版(整合中文分词)源码修改,编译打包。
Java
4
star
58

sqoop-tutorial

Sqoop 2 Java Tutorial
Java
4
star
59

spring-boot-docker-example

Demo project for Spring Boot Docker
Java
4
star
60

spring-boot-oauth2-jdbc-simple

Java
4
star
61

jersey2-restfull-examples

基于jersey2的restfull api接口示例
Java
4
star
62

springcloud-alibaba-example

Spring Cloud Alibaba全家桶整合,一路踩坑(基于最新版本)
Java
4
star
63

springboot-package-example

spring boot 应用多环境打包部署,增量更新、自动化shell脚本
Shell
4
star
64

struts2-spring-compass

Struts2整合Spring3、Hibernate、Compass实现全文检索(基于lucene2.4.1和极易中文分词器)
Java
3
star
65

goblog

基于beego的简易博客
JavaScript
3
star
66

mvn-project-demo

一个maven的项目,含继承和聚合,使用分模块管理和开发
Java
3
star
67

spring-boot-prometheus-grafana-example

Demo project for Spring Boot Prometheus Grafana Sample
Java
3
star
68

spring-mybatis-example

spring-mybatis-example
Java
3
star
69

maven-repo

一个建立在github上的简易maven repo
3
star
70

solr-nutch

solr集成nutch环境(将nutch从互联网上爬取的索引,导入到solr的环境中。使用solr来查询nutch的索引),可以使用solrj api来操作。只是集成环境,solrj的使用参考官方wiki文档
Shell
3
star
71

spring-boot-data-rest-example

Java
2
star
72

shiro-quickstart

shiro-quickstart
Java
2
star
73

image-syncer

aliyun image-syncer https://github.com/AliyunContainerService/image-syncer
2
star
74

spring-cloud-kubernetes-samples

spring-cloud-kubernetes云原生
Java
2
star
75

hive-tutorial

hive jdbc tutorial
Java
2
star
76

hello-spring-cloud-alibaba

spring-cloud-alibaba
Java
2
star
77

taobao-tfs-example

taobao tfs install and config
Java
2
star
78

jbpm4mail

jbpm4之邮件发送例子
Java
2
star
79

netty-chat

Java
2
star
80

websocket

分布式websocket
Java
2
star
81

ebook-downloader

一个现代、实用的国家中小学电子教材下载客户端,使用 Python + flet 构建,支持Windows和macOS平台。
Python
2
star
82

ameizi

2
star
83

sync-docker-image

Sync Docker Image to Docker Hub
Shell
1
star
84

concurrency

java concurrency test
Java
1
star
85

javassist-example

Java
1
star
86

mybatis-plus-codegen

mybatis-plus-codegen
Java
1
star
87

rabbitmq-examples

RabbitMQ使用案例合辑
Java
1
star
88

spring-security-oauth2-samples

spring-security-oauth2-samples
Java
1
star
89

MyBatisGenerator

使用Ant构建MyBatis配置文件
Java
1
star
90

spring-cloud-consul-example

Java
1
star
91

geoip

数据来源 https://dev.maxmind.com/geoip
Shell
1
star
92

spring-boot-jwt-sample

spring-boot-jwt-sample
Java
1
star
93

traefik-lab

Shell
1
star
94

auto-green

1
star
95

jmh-benchmark-sample

jmh benchmark sample
Java
1
star
96

argocd-in-action

1
star
97

springcloud-microservices-sample

Java
1
star
98

go-micro-springcloud-grpc-with-consul

Java
1
star
99

spring-cloud-alibaba-dubbo

spring-cloud-alibaba-dubbo
Java
1
star
100

nats-example

Demo project for Spring Boot NATS
Java
1
star