{"id":15631387,"url":"https://github.com/v5tech/elasticsearch-jest-example","last_synced_at":"2025-04-09T17:26:18.867Z","repository":{"id":23553142,"uuid":"26920432","full_name":"v5tech/elasticsearch-jest-example","owner":"v5tech","description":"ElasticSearch Java Rest Client Examples","archived":false,"fork":false,"pushed_at":"2022-12-16T06:25:54.000Z","size":95,"stargazers_count":188,"open_issues_count":5,"forks_count":137,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-04-02T10:52:46.694Z","etag":null,"topics":["elasticsearch","elasticsearch-jdbc","elasticsearch-jest","jest"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/v5tech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-20T16:12:32.000Z","updated_at":"2024-11-15T15:37:03.000Z","dependencies_parsed_at":"2023-01-13T23:29:03.008Z","dependency_job_id":null,"html_url":"https://github.com/v5tech/elasticsearch-jest-example","commit_stats":null,"previous_names":["v5tech/elasticsearch-jest-example","ameizi/elasticsearch-jest-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Felasticsearch-jest-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Felasticsearch-jest-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Felasticsearch-jest-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Felasticsearch-jest-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/v5tech","download_url":"https://codeload.github.com/v5tech/elasticsearch-jest-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248076207,"owners_count":21043730,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elasticsearch","elasticsearch-jdbc","elasticsearch-jest","jest"],"created_at":"2024-10-03T10:40:14.201Z","updated_at":"2025-04-09T17:26:18.844Z","avatar_url":"https://github.com/v5tech.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"jest\n====\n\nElasticSearch Java Rest Client Examples\n\n### 高亮查询(highlight)\n\n```\nPOST http://127.0.0.1:9200/news/_search?q=李克强\n{\n    \"query\" : {\n        match_all:{}\n    },\n    \"highlight\" : {\n        \"pre_tags\" : [\"\u003cfont color='red'\u003e\", \"\u003cb\u003e\", \"\u003cem\u003e\"],\n        \"post_tags\" : [\"\u003c/font\u003e\", \"\u003cb\u003e\", \"\u003c/em\u003e\"],\n        \"fields\" : [\n            {\"title\" : {}},\n            {\"content\" : {\n                \"fragment_size\" : 350,\n                \"number_of_fragments\" : 3,\n                \"no_match_size\": 150\n            }}\n        ]\n    }\n}\n```\n\n```\nPOST http://127.0.0.1:9200/news/_search?q=李克强\n{\n    \"query\" : {\n        match_all:{}\n    },\n    \"highlight\" : {\n        \"pre_tags\" : [\"\u003cfont color='red'\u003e\u003cb\u003e\u003cem\u003e\"],\n        \"post_tags\" : [\"\u003c/font\u003e\u003cb\u003e\u003c/em\u003e\"],\n        \"fields\" : [\n            {\"title\" : {}},\n            {\"content\" : {\n                \"fragment_size\" : 350,\n                \"number_of_fragments\" : 3,\n                \"no_match_size\": 150\n            }}\n        ]\n    }\n}\n```\n\n### 删除索引\n\nhttps://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html\n\n```\nDELETE http://127.0.0.1:9200/news\n```\n\n### 创建索引\n\nhttps://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html\n\n```\nPUT http://127.0.0.1:9200/news\n```\n\n### 创建或修改mapping\n\nhttps://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html\n\n```\nPUT /{index}/_mapping/{type}\n```\n\n```\nPUT http://127.0.0.1:9200/news/_mapping/article\n{\n  \"article\": {\n    \"properties\": {\n      \"pubdate\": {\n        \"type\": \"date\",\n        \"format\": \"dateOptionalTime\"\n      },\n      \"author\": {\n        \"type\": \"string\"\n      },\n      \"content\": {\n        \"type\": \"string\"\n      },\n      \"id\": {\n        \"type\": \"long\"\n      },\n      \"source\": {\n        \"type\": \"string\"\n      },\n      \"title\": {\n        \"type\": \"string\"\n      },\n      \"url\": {\n        \"type\": \"string\"\n      }\n    }\n  }\n}\n```\n\n### 查看mapping\n\nhttps://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html\n\n\n```\nGET http://127.0.0.1:9200/_all/_mapping\n\nGET http://127.0.0.1:9200/_mapping\n```\n\n```\nGET http://127.0.0.1:9200/news/_mapping/article\n```\n\n输出:\n\n```\n{\n  \"news\": {\n    \"mappings\": {\n      \"article\": {\n        \"properties\": {\n          \"author\": {\n            \"type\": \"string\"\n          },\n          \"content\": {\n            \"type\": \"string\"\n          },\n          \"id\": {\n            \"type\": \"long\"\n          },\n          \"pubdate\": {\n            \"type\": \"date\",\n            \"store\": true,\n            \"format\": \"yyyy-MM-dd HH:mm:ss\"\n          },\n          \"source\": {\n            \"type\": \"string\"\n          },\n          \"title\": {\n            \"type\": \"string\"\n          },\n          \"url\": {\n            \"type\": \"string\"\n          }\n        }\n      }\n    }\n  }\n}\n```\n\n### 删除mapping\n\nhttps://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-mapping.html\n\n```\n[DELETE] /{index}/{type}\n\n[DELETE] /{index}/{type}/_mapping\n\n[DELETE] /{index}/_mapping/{type}\n```\n\n```\nDELETE http://127.0.0.1:9200/news/_mapping/article\n```\n\n### ansj分词器测试\n\nhttp://127.0.0.1:9200/news/_analyze?analyzer=ansj_index\u0026text=习近平\n\nhttp://127.0.0.1:9200/news/_analyze?analyzer=ansj_index\u0026text=我是中国人\n\nhttp://127.0.0.1:9200/news/_analyze?analyzer=ansj_index\u0026text=汪东兴同志遗体在京火化汪东兴同志病重期间和逝世后，习近平李克强张德江俞正声刘云山王岐山张高丽江泽民胡锦涛等同志，前往医院看望或通过各种形式对汪东兴同志逝世表示沉痛哀悼并向其亲属表示深切慰问新华社北京8月27日电中国共产党的优秀党员\n\n### ansj分词器查询\n\n* 普通查询\n\nhttp://127.0.0.1:9200/news/_search?q=习近平\u0026analyzer=ansj_index\u0026size=50\n\n* 指定term查询\n\nhttp://127.0.0.1:9200/news/_search?q=content:江泽民\u0026analyzer=ansj_index\u0026size=50\n\nhttp://127.0.0.1:9200/news/_search?q=title:江泽民\u0026analyzer=ansj_index\u0026size=50\n\nhttp://127.0.0.1:9200/news/_search?q=source:新华网\u0026analyzer=ansj_index\u0026size=50\n\n* 其中`ansj_index`为在`elasticsearch.yml`文件中配置的`ansj`分词器\n\n[elasticsearch rest api 快速上手](https://github.com/ameizi/elasticsearch/issues/5)\n\n### elasticsearch-jdbc\n\n```bash\n@echo off\n\nset DIR=%~dp0\nset LIB=\"%DIR%\\..\\lib\\*\"\nset BIN=\"%DIR%\\..\\bin\\*\"\n\nREM ???\necho {^\n    \"type\" : \"jdbc\",^\n    \"jdbc\" : {^\n        \"url\" : \"jdbc:mysql://localhost:3306/news\",^\n        \"user\" : \"root\",^\n        \"password\" : \"root\",^\n        \"schedule\" : \"0 0/15 * ? * *\",^\n        \"sql\" :  [^\n             {\"statement\":\"SELECT title,content,url,source,author,pubdate FROM news\"},^\n             {^\n                \"statement\":\"SELECT title,content,url,source,author,pubdate FROM news where pubdate \u003e ?\",^\n                \"parameter\" : [ \"$metrics.lastexecutionstart\" ]^\n             }^\n\t],^\n\t\"autocommit\" : true,^\n        \"treat_binary_as_string\" : true,^\n        \"elasticsearch\" : {^\n             \"cluster\" : \"elasticsearch\",^\n             \"host\" : \"localhost\",^\n             \"port\" : 9300^\n        },^\n        \"index\" : \"news\",^\n        \"type\" : \"article\"^\n      }^\n}^ | \"%JAVA_HOME%\\bin\\java\" -cp \"%LIB%\" -Dlog4j.configurationFile=\"file://%DIR%\\log4j2.xml\" \"org.xbib.tools.Runner\" \"org.xbib.tools.JDBCImporter\"\n```\n\n[elasticsearch-jdbc 插件的使用](https://github.com/ameizi/elasticsearch/issues/3)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fv5tech%2Felasticsearch-jest-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fv5tech%2Felasticsearch-jest-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fv5tech%2Felasticsearch-jest-example/lists"}