学习 Elasticsearch 敲过的指令

本贴最后更新于 2810 天前,其中的信息可能已经时过境迁

—— from《Elasticsearch: The Definitive Guide》

curl -XGET http://localhost:9200/_count?pretty -d '
{
    "query":{
        "match_all":{}
    }
}'

curl -i -XGET http://localhost:9200/

curl -XPUT http://localhost:9200/megacorp/employee/1?pretty -d '
{
    "first_name":"John",
    "last_name":"Smith",
    "age":25,
    "about":"I love to go rock climbing",
    "interests":["sports","music"]
}'

curl -XPUT http://localhost:9200/megacorp/employee/2?pretty -d '
{
    "first_name":"Jane",
    "last_name":"Smith",
    "age":32,
    "about":"I like to collect rock albums",
    "interests":["music"]
}'

curl -XPUT http://localhost:9200/megacorp/employee/3?pretty -d '
{
    "first_name":"Douglas",
    "last_name":"Fir",
    "age":35,
    "about":"I like to build cabinets",
    "interests":["forestry"]
}'

curl -XGET http://localhost:9200/megacorp/employee/1?pretty

curl -XGET http://localhost:9200/megacorp/employee/_search?pretty

curl -XGET http://localhost:9200/megacorp/employee/_search?q=last_name:Smith&pretty

curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
    "query":{
        "match":{
            "last_name":"Smith"
        }
    }
}'

curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
    "query":{
        "filtered":{
            "filter":{
                "range":{
                    "age":{
                        "gt":30
                    }
                }
            },
            "query":{
                "match":{
                    "last_name":"smith"
                }
            }
        }
    }
}'

curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
    "query":{
        "match":{
            "about":"rock climbing"
        }
    }
}'

curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
    "query":{
        "match_phrase":{
            "about":"rock climbing"
        }
    }
}'

curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
    "query":{
        "match_phrase":{
            "about":"rock climbing"
        }
    },
    "highlight":{
        "fields":{
            "about":{}
        }
    }
}'

curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
    "aggs":{
        "all_interests":{
            "terms":{
                "field":"interests"
            }
        }
    }
}'

curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
    "query":{
        "match":{
            "last_name":"smith"
        }
    },
    "aggs":{
        "all_interests":{
            "terms":{
                "field":"interests"
            }
        }
    }
}'

curl -XGET http://localhost:9200/megacorp/employee/_search?pretty -d '
{
    "aggs":{
        "all_interests":{
            "terms":{
                "field":"interests"
            },
            "aggs":{
                "avg_age":{
                    "avg":{
                        "field":"age"
                    }
                }
            }
        }
    }
}'

curl -XGET http://localhost:9200/_cluster/health?pretty

curl -XPUT http://localhost:9200/blogs?pretty -d '
{
    "number_of_shards":3,
    "number_of_replicas":1
}'

curl -XPUT http://localhost:9200/blogs/_settings?pretty -d '
{
    "number_of_replicas":2
}'

curl -XPUT http://localhost:9200/website/blog/123?pretty -d '
{
    "title":"My first blog entry",
    "text":"Just trying this out...",
    "date":"2014/01/01"
}'

curl -XPOST http://localhost:9200/website/blog/?pretty -d '
{
    "title":"My second blog entry",
    "text":"Still trying this out...",
    "date":"2014/01/01"
}'

curl -XGET http://localhost:9200/website/blog/123?pretty

curl -i -XGET http://localhost:9200/website/blog/124?pretty

curl -XGET http://localhost:9200/website/blog/123?pretty&_source=title,text

curl -XGET http://localhost:9200/website/blog/123/_source

curl -i -XHEAD http://localhost:9200/website/blog/123

curl -i -XHEAD http://localhost:9200/website/blog/124

curl -XPUT http://localhost:9200/website/blog/123?pretty -d '
{
    "title":"My first blog entry",
    "text":"I am starting to get the hang of this...",
    "date":"2014/01/02"
}'

curl -XDELETE http://localhost:9200/website/blog/123?pretty

curl -XPUT http://localhost:9200/website/blog/1/_create?pretty -d '
{
    "title":"My first blog entry",
    "text":"Just trying this out..."
}'

curl -XGET http://localhost:9200/website/blog/1?pretty

curl -XPUT http://localhost:9200/website/blog/1?version=1&pretty -d '
{
    "title":"My first blog entry",
    "text":"starting to get the hang of this..."
}'

curl -XPUT http://localhost:9200/website/blog/2?version=5&version_type=external&pretty -d '
{
    "title":"My first external blog entry",
    "text":"Starting to get the hang of this..."
}'

curl -XPUT http://localhost:9200/website/blog/2?version=10&version_type=external&pretty -d '
{
    "title":"My first external blog entry",
    "text":"This is a piece of cake..."
}'

curl -XPOST http://localhost:9200/website/blog/1/_update?pretty -d '
{
    "doc":{
        "tags":["testing"],
        "views":0
    }
}'

curl -XPOST http://localhost:9200/website/blog/1/_update?pretty -d '
{
    "script":"ctx._source.views+=1"
}'

curl -XPOST http://localhost:9200/website/blog/1/_update?pretty -d '
{
	"script":"ctx._source.tags+=new_tag",
	"params":{
		"new_tag":"search"
	}
}'

curl -XPOST http://localhost:9200/website/blog/1/_update?pretty -d '
{
	"script":"ctx.op = ctx._source.views == count ? '"'"'delete'"'"' : '"'"'none'"'",
	"params":{
		"count":1
	}
}'

curl -XPOST http://localhost:9200/website/pageviews/1/_update?pretty -d '
{
	"script":"ctx._source.views+=1",
	"upsert":{
		"views":1
	}
}'

curl -XPOST http://localhost:9200/website/pageviews/1/_update?pretty&retry_on_conflict=5 -d '
{
	"script":"ctx._source.views+=1",
	"upsert":{
		"views":0
	}
}'

curl -XGET http://localhost:9200/_mget?pretty -d '
{
	"docs":[
		{
			"_index":"website",
			"_type":"blog",
			"_id":2
		},
		{
			"_index":"website",
			"_type":"pageviews",
			"_id":1,
			"_source":"views"
		}
	]
}'

curl -XGET http://localhost:9200/website/blog/_mget?pretty -d '
{
	"docs":[
		{
			"_id":2
		},
		{
			"_type":"pageviews",
			"_id":1
		}
	]
}'

curl -XGET http://localhost:9200/website/blog/_mget?pretty -d '
{
	"ids":["2","1"]
}'

curl -XPOST http://localhost:9200/_bulk?pretty -d '
{"delete":{"_index":"website","_type":"blog","_id":"123"}}
{"create":{"_index":"website","_type":"blog","_id":"123"}}
{"title":"My first blog post"}
{"index":{"_index":"website","_type":"blog"}}
{"title":"My second blog post"}
{"update":{"_index":"website","_type":"blog","_id":"123","_retry_on_conflict":3}}
{"doc":{"title":"My updated blog post"}}
'

curl -XPOST http://localhost:9200/_bulk?pretty -d '
{"create":{"_index":"website","_type":"blog","_id":"123"}}
{"title":"Cannot create - it already exists"}
{"index":{"_index":"website","_type":"blog","_id":"123"}}
{"title":"But we can update it"}
'

curl -XPOST http://localhost:9200/website/_bulk?pretty -d '
{"index":{"_type":"log"}}
{"event":"User logged in"}
'

curl -XPOST http://localhost:9200/website/log/_bulk?pretty -d '
{"index":{}}
{"event":"User logged in"}
{"index":{"_type":"blog"}}
{"title":"Overriding the default type"}
'

curl -XGET http://localhost:9200/_search\?pretty

curl -XGET http://localhost:9200/_search?pretty&size=10&from=10

curl -XGET http://localhost:9200/gb/_mapping/tweet

curl -XGET http://lcoalhost:9200/ikyxxs/_mapping/faq?pretty

curl -XFELETE http://localhost:9200/gb

curl -XPUT http://localhost:9200/gb?pretty -d '
{
	"mappings":{
		"tweet":{
			"properties":{
				"tweet":{
					"type":"string",
					"analyzer":"english"
				},
				"date":{
					"type":"date"
				},
				"name":{
					"type":"string"
				},
				"user_id":{
					"type":"long"
				}
			}
		}
	}
}'

curl -XPUT http://localhost:9200/gb_mapping/tweeet -d '
{
	"properties":{
		"tag":{
			"type":"string",
			"index":"not_analyzed"
		}
	}
}'

curl -XGET http://localhost:9200/gb/_analyze?field=tweet&pretty -d '
Black-cats'

curl -XGET http://localhost:9200/gb/_analyze?field=tag?pretty -d '
Black-cats'

curl -XGET http://localhost:9200/_search?pretty -d '
{
	"query":{
		"match_all":{}
	}
}'

curl -XGET http://localhost:9200/_search?pretty -d '
{
	"query":{
		"match":{
			"tweet":"elasticsearch"
		}
	}
}'

curl -XGET http://localhost:9200/_search?pretty -d '
{
	"query":{
		"filtered":{
			"query":{
				"match_all":{}
			},
			"filter":{
				"term":{
					"folder":"inbox"
				}
			}
		}
	}
}'

curl -XGET http://localhost:9200/_search?pretty -d '
{
	"query":{
		"filtered":{
			"filter":{
				"bool":{
					"must":{
						"term":{
							"folder":"inbox"
						}
					},
					"must_not":{
						"query":{
							"match":{
								"email":"urgent business proposal"
							}
						}
					}
				}
			}
		}
	}
}'

curl -XGET http://localhost:9200/gb/tweet/_validate/query?pretty -d '
{
	"query":{
		"tweet":{
			"match":"really powerful"
		}
	}
}'

curl -XGET http://localhost:9200/gb/tweet/_validate/query?explain&pretty -d '
{
	"query":{
		"tweet":{
			"match":"really powerful"
		}
	}
}'

curl -XGET http://localhost:9200/_validate/query?explain&pretty -d '
{
	"query":{
		"match":{
			"tweet":"really powerful"
		}
	}
}'

curl -XGET http://localhost:9200/_search?pretty -d '
{
	"query":{
		"filtered":{
			"filter":{
				"term":{
					"user_id":1
				}
			}
		}
	}
}'

curl -XGET http://localhost:9200/_search?pretty -d '
{
	"query":{
		"filtered":{
			"filter":{
				"term":{
					"user_id":1
				}
			}
		}
	},
	"sort":{
		"date":{
			"order":"desc"
		}
	}
}'

curl -XGET http://localhost:9200/_search?pretty -d '
{
	"query":{
		"filtered":{
			"query":{
				"match":{
					"tweet":"manage text search"
				}
			},
			"filter":{
				"term":{
					"user_id":2
				}
			}
		}
	},
	"sort":[
		{
			"date":{
				"order":"desc"
			}
		},
		{
			"_score":{
				"order":desc
			}
		}
	]
}'

curl -XGET http://localhost:9200/_search?pretty&sort=date:desc&sort=_score&q=search 

curl -XGET http://localhost:9200/_search?pretty -d '
{
	"query":{
		"match":{
			"tweet":"elasticsearch"
		}
	},
	"sort":"tweet.raw"
}'

curl -XGET http://localhost:9200/_search?pretty&explain -d '
{
	"query":{
		"match":{
			"tweet":"honeymoon"
		}
	}
}'

curl -XGET http://localhost:9200/us/tweet/12/_explain -d '
{
	"query":{
		"filtered":{
			"filter":{
				"term":{
					"user_id":2
				}
			},
			"query":{
				"match":{
					"tweet":"honeymoon"
				}
			}
		}
	}
}'

curl -XGET http://localhost:9200/_search?pretty -d '
{
	"from":90,
	"size":10
}'

curl -XGET http://localhost:9200/_search?pretty&routing=user_1,user2

curl -XGET http://localhost:9200/_search?pretty&search_type=count

curl -XGET http://localhost:9200/old_index/_search?search_type=scan&scroll=1m -d '
{
	"query":{
		"match_all":{}
	},
	"size":1000
}'

curl -XDELETE http://localhost:9200/my_index

curl -XDELETE http://localhost:9200/index_one,index_two

curl -XDELETE http://localhost:9200/index_*

curl -XDELETE http://localhost:9200/_all

curl -XPUT http://localhost:9200/my_temp_index?pretty -d '
{
	"settings":{
		"number_of_shards": 1,
		"number_of_replicas": 0
	}
}'

curl -XPUT http://localhost:9200/my_temp_index/_settings?pretty -d '
{
	"number_of_replicas": 1
}'

curl -XPUT http://localhost:9200/spanish_docs?pretty -d '
{
	"settings":{
		"analysis":{
			"anlayzer":{
				"es_std":{
					"type":"standard",
					"stopwords":"_spanish_"
				}
			}
		}
	}
}'

curl -XGET http://localhost:9200/spanish_docs/_analyze?pretty&analyzer=es_std -d '
El veloz zorro marron'

curl -XPUT http://localhost:9200/my_index?pretty -d '
{
	"settings":{
		"analysis":{
			"char_filter":{
				"&_to_and":{
					"type":"mapping",
					"mappings":["&=> and"]
				}
			},
			"filter":{
				"my_stopwords":{
					"type":"stop",
					"stopwords":["the","a"]
				}
			},
			"analyzer":{
				"my_analyzer":{
					"type":"custom",
					"char_filter":["html_strip", "&_to_end"],
					"tokenizer":"standard",
					"filter":["lowercase", "my_stopwords"]
				}
			}
		}
	}
}'

curl -XGET http://localhost:9200/my_index/_analyze?analyzer=my_analyzer?pretty -d '
The quick & brown fox'

curl -XPUT http://localhost:9200/my_index/_mapping/my_type?pretty -d '
{
	"properties":{
		"title":{
			"type":"string",
			"analyzer":"my_analyzer"
		}
	}
}'

curl -XGET http://localhost:9200/_seach?pretty -d '
{
	"query":{
		"match":{
			"title":"The quick brown fox"
		}
	}
}'


curl -XGET http://localhost:9200/_search?pretty -d '
{
	"query":{
		"multi_match":{
			"query":"The quick brown fox",
			"fields":["blog_en.title", "blog_es.title"]
		}
	}
}'

curl -XPUT http://localhost:9200/my_index?prertty -d '
{
	"mappings":{
		"my_type":{
			"_source":{
				"ebable":false
			}
		}
	}
}'


curl -XGET http://localhost:9200/_search?pretty -d '
{
	"query":{
		"match_all":{}
	},
	"_source":["title", "created"]
}'

curl -XGET http://localhost:9200/_search?pretty -d '
{
	"match":{
		"_all": "john smith marketing"
	}
}'

curl -XPUT http://localhost:9200/my_index/_mapping/my_type?pretty -d '
{
	"my_type":{
		"_all": {
			"enabled":false
		}
	}
}'

curl -XPUT http://localhost:9200/my_index/my_type/_mapping?pretty -d '
{
	"my_type":{
		"_all": {
			"analyzer":"whitespace"
		}
	}
}'

curl -XPUT http://localhost:9200/my_index?pretty -d '
{
	"mapping":{
		"my_type":{
			"_id":{
				"path":"doc_id"
			},
			"properties":{
				"doc_id":{
					"type":"string",
					"index":"not_analyzed"
				}
			}
		}
	}
}'

curl -XPOST http://localhost:9200/my_index/my_type?pretty -d '
{
	"doc_id":"123"
}'

  • Elasticsearch

    Elasticsearch 是一个基于 Lucene 的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于 RESTful 接口。Elasticsearch 是用 Java 开发的,并作为 Apache 许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。

    116 引用 • 99 回帖 • 249 关注

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...
mubai
洛阳亲友如相问,就说我在写代码 杭州

推荐标签 标签

  • BAE

    百度应用引擎(Baidu App Engine)提供了 PHP、Java、Python 的执行环境,以及云存储、消息服务、云数据库等全面的云服务。它可以让开发者实现自动地部署和管理应用,并且提供动态扩容和负载均衡的运行环境,让开发者不用考虑高成本的运维工作,只需专注于业务逻辑,大大降低了开发者学习和迁移的成本。

    19 引用 • 75 回帖 • 616 关注
  • frp

    frp 是一个可用于内网穿透的高性能的反向代理应用,支持 TCP、UDP、 HTTP 和 HTTPS 协议。

    16 引用 • 7 回帖 • 2 关注
  • 服务器

    服务器,也称伺服器,是提供计算服务的设备。由于服务器需要响应服务请求,并进行处理,因此一般来说服务器应具备承担服务并且保障服务的能力。

    124 引用 • 580 回帖
  • Flume

    Flume 是一套分布式的、可靠的,可用于有效地收集、聚合和搬运大量日志数据的服务架构。

    9 引用 • 6 回帖 • 613 关注
  • Kotlin

    Kotlin 是一种在 Java 虚拟机上运行的静态类型编程语言,由 JetBrains 设计开发并开源。Kotlin 可以编译成 Java 字节码,也可以编译成 JavaScript,方便在没有 JVM 的设备上运行。在 Google I/O 2017 中,Google 宣布 Kotlin 成为 Android 官方开发语言。

    19 引用 • 33 回帖 • 51 关注
  • 程序员

    程序员是从事程序开发、程序维护的专业人员。

    544 引用 • 3531 回帖
  • 区块链

    区块链是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。所谓共识机制是区块链系统中实现不同节点之间建立信任、获取权益的数学算法 。

    91 引用 • 751 回帖
  • SQLServer

    SQL Server 是由 [微软] 开发和推广的关系数据库管理系统(DBMS),它最初是由 微软、Sybase 和 Ashton-Tate 三家公司共同开发的,并于 1988 年推出了第一个 OS/2 版本。

    19 引用 • 31 回帖 • 2 关注
  • 面试

    面试造航母,上班拧螺丝。多面试,少加班。

    324 引用 • 1395 回帖 • 1 关注
  • Swagger

    Swagger 是一款非常流行的 API 开发工具,它遵循 OpenAPI Specification(这是一种通用的、和编程语言无关的 API 描述规范)。Swagger 贯穿整个 API 生命周期,如 API 的设计、编写文档、测试和部署。

    26 引用 • 35 回帖
  • Ruby

    Ruby 是一种开源的面向对象程序设计的服务器端脚本语言,在 20 世纪 90 年代中期由日本的松本行弘(まつもとゆきひろ/Yukihiro Matsumoto)设计并开发。在 Ruby 社区,松本也被称为马茨(Matz)。

    7 引用 • 31 回帖 • 196 关注
  • NGINX

    NGINX 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 NGINX 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本 0.1.0 发布于 2004 年 10 月 4 日。

    311 引用 • 546 回帖
  • 快应用

    快应用 是基于手机硬件平台的新型应用形态;标准是由主流手机厂商组成的快应用联盟联合制定;快应用标准的诞生将在研发接口、能力接入、开发者服务等层面建设标准平台;以平台化的生态模式对个人开发者和企业开发者全品类开放。

    15 引用 • 127 回帖 • 1 关注
  • 分享

    有什么新发现就分享给大家吧!

    245 引用 • 1776 回帖 • 1 关注
  • Ubuntu

    Ubuntu(友帮拓、优般图、乌班图)是一个以桌面应用为主的 Linux 操作系统,其名称来自非洲南部祖鲁语或豪萨语的“ubuntu”一词,意思是“人性”、“我的存在是因为大家的存在”,是非洲传统的一种价值观,类似华人社会的“仁爱”思想。Ubuntu 的目标在于为一般用户提供一个最新的、同时又相当稳定的主要由自由软件构建而成的操作系统。

    123 引用 • 168 回帖
  • jsoup

    jsoup 是一款 Java 的 HTML 解析器,可直接解析某个 URL 地址、HTML 文本内容。它提供了一套非常省力的 API,可通过 DOM,CSS 以及类似于 jQuery 的操作方法来取出和操作数据。

    6 引用 • 1 回帖 • 473 关注
  • 负能量

    上帝为你关上了一扇门,然后就去睡觉了....努力不一定能成功,但不努力一定很轻松 (° ー °〃)

    88 引用 • 1234 回帖 • 441 关注
  • abitmean

    有点意思就行了

    39 关注
  • 资讯

    资讯是用户因为及时地获得它并利用它而能够在相对短的时间内给自己带来价值的信息,资讯有时效性和地域性。

    54 引用 • 85 回帖
  • gRpc
    11 引用 • 9 回帖 • 49 关注
  • TensorFlow

    TensorFlow 是一个采用数据流图(data flow graphs),用于数值计算的开源软件库。节点(Nodes)在图中表示数学操作,图中的线(edges)则表示在节点间相互联系的多维数据数组,即张量(tensor)。

    20 引用 • 19 回帖 • 1 关注
  • 运维

    互联网运维工作,以服务为中心,以稳定、安全、高效为三个基本点,确保公司的互联网业务能够 7×24 小时为用户提供高质量的服务。

    148 引用 • 257 回帖
  • 锤子科技

    锤子科技(Smartisan)成立于 2012 年 5 月,是一家制造移动互联网终端设备的公司,公司的使命是用完美主义的工匠精神,打造用户体验一流的数码消费类产品(智能手机为主),改善人们的生活质量。

    4 引用 • 31 回帖 • 8 关注
  • ngrok

    ngrok 是一个反向代理,通过在公共的端点和本地运行的 Web 服务器之间建立一个安全的通道。

    7 引用 • 63 回帖 • 613 关注
  • CAP

    CAP 指的是在一个分布式系统中, Consistency(一致性)、 Availability(可用性)、Partition tolerance(分区容错性),三者不可兼得。

    11 引用 • 5 回帖 • 580 关注
  • 游戏

    沉迷游戏伤身,强撸灰飞烟灭。

    171 引用 • 814 回帖
  • ActiveMQ

    ActiveMQ 是 Apache 旗下的一款开源消息总线系统,它完整实现了 JMS 规范,是一个企业级的消息中间件。

    19 引用 • 13 回帖 • 641 关注