Linux 6.4 安装 elastic search及使用命令

//安装的部分此处请参考: https://blog.csdn.net/yjclsx/article/details/81302041

//此部分设置jdk 1.8 并使之生效
export JAVA_HOME=/opt/jdk1.8.0_60
export PATH=.: J A V A H O M E / b i n : JAVA_HOME/bin: JAVAHOME/bin:PATH
export CLASSPATH=: J A V A H O M E / l i b / d t . j a r : JAVA_HOME/lib/dt.jar: JAVAHOME/lib/dt.jar:JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib

//如果报进程 ERROR: [1] bootstrap checks failed [1]: max number of threads [1024] for user [elasticsearch] is too low, increase to at least [2048],且修改90-nproc.conf无效,可以使用以下命令启动
ulimit -u 4096

/home/hadoop/app/elasticsearch-6.2.4
nohup /home/hadoop/app/elasticsearch-6.2.4/bin/elasticsearch > /tmp/elasticsearch.log &

//1) put 插入
curl -XPOST ‘localhost:9200/product/book/1?pretty’ -H ‘Content-Type:application/json’ -d’
{
“name”:“北京100种小吃”,
“type”:“food”,
“postDate”:“2009-11-15”,
“message”:“介绍了北京小吃,如炸酱面、卤煮、驴打滚等”
}

curl -XPOST ‘localhost:9200/product/book/2?pretty’ -H ‘Content-Type:application/json’ -d’
{
“name”:“上海100种小吃”,
“type”:“food”,
“postDate”:“2009-11-15”,
“message”:“介绍了上海小吃,如炸酱面、卤煮、驴打滚等”
}

//2) 读取
curl -XGET ‘localhost:9200/product/book/1/_source?pretty’
curl -XGET ‘localhost:9200/product/book/2/_source?pretty’

//3) 全部更新
curl -XPUT ‘localhost:9200/product/book/1?pretty’ -H ‘Content-Type:application/json’ -d’
{
“name”:“北京100种小吃111”,
“type”:“food”,
“postDate”:“2009-11-15”,
“message”:“介绍了北京小吃,如炸酱面、卤煮、驴打滚等”
}

curl -XPUT ‘localhost:9200/product/book/2?pretty’ -H ‘Content-Type:application/json’ -d’
{
“name”:“上海100种小吃”,
“type”:“food”,
“postDate”:“2009-11-15”,
“message”:“介绍了上海小吃,如小馄饨、小笼包、眉毛酥等”
}

curl -XPUT ‘localhost:9200/product/book/3?pretty’ -H ‘Content-Type:application/json’ -d’
{
“name”:“苏州100种小吃”,
“type”:“film”,
“postDate”:“2009-11-15”,
“message”:“介绍了苏州小吃,如素面、观前街、评弹等”
}

//3) 部分更新
curl -XPOST ‘localhost:9200/product/book/1/_update’ -H ‘Content-Type:application/json’ -d’
{
“doc”: {
“message”:“介绍了北京小吃,如炸酱面、卤煮、驴打滚,还有豆汁等”
}
}

//3) 部分更新,且根据乐观锁更新内容 version=xxx
curl -XPOST ‘localhost:9200/product/book/1/_update?pretty&version=6’ -H ‘Content-Type:application/json’ -d’
{
“doc”: {
“message”:“介绍了北京小吃,如炸酱面、卤煮、驴打滚,还有豆汁等111”
}
}

//4) 删除
curl -XDELETE ‘localhost:9200/product/book/1/?pretty’

//搜索-get方法
curl -G --data-urlencode ‘q=message:驴打滚’ ‘localhost:9200/product/book/_search?pretty’
curl -G --data-urlencode ‘q=message:上海’ ‘localhost:9200/product/book/_search?pretty’
curl -G --data-urlencode ‘q=message:北京’ ‘localhost:9200/product/book/_search?pretty’

//搜索-post 全文方式
curl -XPOST ‘localhost:9200/product/book/_search?pretty’ -H ‘Content-Type:application/json’ -d’
{
“query”: {
“match”: {“message”:“上海”}
}
}

//5) 搜索-精确搜索方式
curl -XGET ‘localhost:9200/product/book/_search?pretty’ -H ‘Content-Type:application/json’ -d’
{
“query”: {
“term”: {“type”:“food”}
}
}

//5) 搜索-查询总数 - type=food
curl -XGET ‘localhost:9200/product/book/_count?pretty’ -H ‘Content-Type:application/json’ -d’
{
“query”: {
“term”: {“type”:“food”}
}
}

//5) 搜索-查询总数 - type=film
curl -XGET ‘localhost:9200/product/book/_count?pretty’ -H ‘Content-Type:application/json’ -d’
{
“query”: {
“term”: {“type”:“film”}
}
}

//5) 搜索-联合查询
//5.1 where message like ‘’
curl -XGET ‘localhost:9200/product/book/_search?pretty’ -H ‘Content-Type:application/json’ -d’
{
“from”:0,“size”:5,
“query”:{
“bool”:{
“must”:{ “match”:{ “message”:“驴打滚” }}
}
}
}

//5.2 where type = film
curl -XGET ‘localhost:9200/product/book/_search?pretty’ -H ‘Content-Type:application/json’ -d’
{
“from”:0,“size”:5,
“query”:{
“bool”:{
“must”:{ “term” :{ “type” :“film” }}
}
}
}

//5.3 column1 like ‘’ and column2 =
curl -XGET ‘localhost:9200/product/book/_search?pretty’ -H ‘Content-Type:application/json’ -d’
{
“from”:0,“size”:5,
“query”: {
“bool”: {
“must”:[{“match”:{“message”:“驴打滚”}},{“term”:{“type”:“food”}}]
}
}
}

//5.3 column1 like ‘’ and column2 <> ‘’
curl -XGET ‘localhost:9200/product/book/_search?pretty’ -H ‘Content-Type:application/json’ -d’
{
“from”:0,“size”:5,
“query”: {
“bool”: {
“must”:[{“match”:{“message”:“小吃”}},{“term”:{“type”:“food”}}],
“must_not”:{“match”:{“type”:“film”}}
}
}
}

你可能感兴趣的:(elastic,search,elastic,search,安装,使用)