You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
health status index pri rep docs.count docs.deleted store.size pri.store.size
yellow open .marvel-2015.09.11 1 1 3233 0 10.5mb 10.5mb
yellow open .marvel-2015.09.10 1 1 1996 0 3.9mb 3.9mb
yellow open news 5 1 3455 0 17.8mb 17.8mb
创建索引
使用PUT请求创建一个countries的索引
curl -XPUT http://127.0.0.1:9200/countries?pretty
输出:
{
"acknowledged": true
}
查看索引列表
curl -XGET http://127.0.0.1:9200/_cat/indices?v
输出:
health status index pri rep docs.count docs.deleted store.size pri.store.size
yellow open countries 5 1 0 0 575b 575b
yellow open .marvel-2015.09.11 1 1 3436 0 11.4mb 11.4mb
yellow open .marvel-2015.09.10 1 1 1996 0 3.9mb 3.9mb
yellow open news 5 1 3455 0 17.8mb 17.8mb
elasticsearch rest api 快速上手
遵循的格式为
集群健康查看
列出所有的indices
创建索引
使用
PUT
请求创建一个countries的索引输出:
查看索引列表
输出:
索引文档
使用
PUT
请求创建一个索引为countries
类型为country
的文档。其文档编号为1
,文档内容包含name
和capital
输出:
注意:使用系统分配的id时使用
POST
方式提交文档,且在索引\类型
url格式中不再有id输出:
查询文档
使用自定义id查询文档
输出:
使用系统分配的id查询
输出:
查看索引信息
输出:
删除索引
删除
myindex
索引输出:
索引或替换一个文档
根据文档id索引或替换文档,若存在则修改替换,否则索引该文档。
修改文档id为1的国家信息。
查询其是否已修改
输出:
可见国家信息已由
中国
变为日本
,其首都信息也发生了变化输出:
修改文档
以
doc
方式修改文档id为1的文档其中
doc
是固定写法,其内容为要修改的文档内容以
script
方式修改文档id为1的文档删除文档
输出:
输出:
查询是否还有name为美国的文档
批量处理
_bulk api
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
遵循格式
/_bulk, /{index}/_bulk, {index}/{type}/_bulk
支持的action有
index
,create
,delete
,update
index
和create
在下一行跟上要索引的docdelete
则不需要update
在下一行跟上doc
或script
以上请求将会批量索引6个文档。
输出:
输出:
countries.json
使用curl的
--data-binary
参数导入数据或者使用postman导入
search api
注:
q=*
将匹配索引中的所有文档输出:
输出:
size
控制返回条目,默认为10输出:
使用
from
和size
来翻页。其中form
默认为0
,size
默认为10
其中
name
为排序字段限定返回字段
使用
_source
来限定返回的字段。这里只返回name
高级查询
按
name
统计分组文档数输出:
高亮查询(highlight)
删除索引
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html
创建索引
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
创建或修改mapping
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html
查看mapping
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html
输出:
删除mapping
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-mapping.html
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=汪东兴同志遗体在京火化%20汪东兴同志病重期间和逝世后,习近平李克强张德江俞正声刘云山王岐山张高丽江泽民胡锦涛等同志,%20前往医院看望或通过各种形式对汪东兴同志逝世表示沉痛哀悼并向其亲属表示深切慰问%20新华社北京8月27日电中国共产党的优秀党员
ansj分词器查询
http://127.0.0.1:9200/news/_search?q=习近平&analyzer=ansj_index&size=50
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
分词器The text was updated successfully, but these errors were encountered: