学习 Elasticsearch 敲过的指令

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

—— 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 回帖 • 267 关注

相关帖子

欢迎来到这里!

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

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

推荐标签 标签

  • Facebook

    Facebook 是一个联系朋友的社交工具。大家可以通过它和朋友、同事、同学以及周围的人保持互动交流,分享无限上传的图片,发布链接和视频,更可以增进对朋友的了解。

    4 引用 • 15 回帖 • 454 关注
  • iOS

    iOS 是由苹果公司开发的移动操作系统,最早于 2007 年 1 月 9 日的 Macworld 大会上公布这个系统,最初是设计给 iPhone 使用的,后来陆续套用到 iPod touch、iPad 以及 Apple TV 等产品上。iOS 与苹果的 Mac OS X 操作系统一样,属于类 Unix 的商业操作系统。

    84 引用 • 139 回帖 • 1 关注
  • Spring

    Spring 是一个开源框架,是于 2003 年兴起的一个轻量级的 Java 开发框架,由 Rod Johnson 在其著作《Expert One-On-One J2EE Development and Design》中阐述的部分理念和原型衍生而来。它是为了解决企业应用开发的复杂性而创建的。框架的主要优势之一就是其分层架构,分层架构允许使用者选择使用哪一个组件,同时为 JavaEE 应用程序开发提供集成的框架。

    941 引用 • 1458 回帖 • 152 关注
  • CSDN

    CSDN (Chinese Software Developer Network) 创立于 1999 年,是中国的 IT 社区和服务平台,为中国的软件开发者和 IT 从业者提供知识传播、职业发展、软件开发等全生命周期服务,满足他们在职业发展中学习及共享知识和信息、建立职业发展社交圈、通过软件开发实现技术商业化等刚性需求。

    14 引用 • 155 回帖
  • 设计模式

    设计模式(Design pattern)代表了最佳的实践,通常被有经验的面向对象的软件开发人员所采用。设计模式是软件开发人员在软件开发过程中面临的一般问题的解决方案。这些解决方案是众多软件开发人员经过相当长的一段时间的试验和错误总结出来的。

    198 引用 • 120 回帖
  • 30Seconds

    📙 前端知识精选集,包含 HTML、CSS、JavaScript、React、Node、安全等方面,每天仅需 30 秒。

    • 精选常见面试题,帮助您准备下一次面试
    • 精选常见交互,帮助您拥有简洁酷炫的站点
    • 精选有用的 React 片段,帮助你获取最佳实践
    • 精选常见代码集,帮助您提高打码效率
    • 整理前端界的最新资讯,邀您一同探索新世界
    488 引用 • 383 回帖 • 4 关注
  • Sandbox

    如果帖子标签含有 Sandbox ,则该帖子会被视为“测试帖”,主要用于测试社区功能,排查 bug 等,该标签下内容不定期进行清理。

    370 引用 • 1215 回帖 • 582 关注
  • SOHO

    为成为自由职业者在家办公而努力吧!

    7 引用 • 55 回帖 • 93 关注
  • Swift

    Swift 是苹果于 2014 年 WWDC(苹果开发者大会)发布的开发语言,可与 Objective-C 共同运行于 Mac OS 和 iOS 平台,用于搭建基于苹果平台的应用程序。

    34 引用 • 37 回帖 • 499 关注
  • danl
    65 关注
  • Bootstrap

    Bootstrap 是 Twitter 推出的一个用于前端开发的开源工具包。它由 Twitter 的设计师 Mark Otto 和 Jacob Thornton 合作开发,是一个 CSS / HTML 框架。

    18 引用 • 33 回帖 • 684 关注
  • C++

    C++ 是在 C 语言的基础上开发的一种通用编程语言,应用广泛。C++ 支持多种编程范式,面向对象编程、泛型编程和过程化编程。

    106 引用 • 152 回帖 • 1 关注
  • 微信

    腾讯公司 2011 年 1 月 21 日推出的一款手机通讯软件。用户可以通过摇一摇、搜索号码、扫描二维码等添加好友和关注公众平台,同时可以将自己看到的精彩内容分享到微信朋友圈。

    129 引用 • 793 回帖 • 1 关注
  • ZooKeeper

    ZooKeeper 是一个分布式的,开放源码的分布式应用程序协调服务,是 Google 的 Chubby 一个开源的实现,是 Hadoop 和 HBase 的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。

    59 引用 • 29 回帖 • 21 关注
  • 人工智能

    人工智能(Artificial Intelligence)是研究、开发用于模拟、延伸和扩展人的智能的理论、方法、技术及应用系统的一门技术科学。

    75 引用 • 146 回帖 • 1 关注
  • CAP

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

    11 引用 • 5 回帖 • 566 关注
  • Bug

    Bug 本意是指臭虫、缺陷、损坏、犯贫、窃听器、小虫等。现在人们把在程序中一些缺陷或问题统称为 bug(漏洞)。

    77 引用 • 1741 回帖 • 1 关注
  • 又拍云

    又拍云是国内领先的 CDN 服务提供商,国家工信部认证通过的“可信云”,乌云众测平台认证的“安全云”,为移动时代的创业者提供新一代的 CDN 加速服务。

    21 引用 • 37 回帖 • 512 关注
  • Electron

    Electron 基于 Chromium 和 Node.js,让你可以使用 HTML、CSS 和 JavaScript 构建应用。它是一个由 GitHub 及众多贡献者组成的活跃社区共同维护的开源项目,兼容 Mac、Windows 和 Linux,它构建的应用可在这三个操作系统上面运行。

    15 引用 • 136 回帖 • 6 关注
  • Sillot

    Sillot (汐洛)孵化自思源笔记,致力于服务智慧新彖乄,具有彖乄驱动、极致优雅、开发者友好的特点
    Github 地址:https://github.com/Hi-Windom/Sillot

    16 引用 • 6 回帖 • 28 关注
  • 七牛云

    七牛云是国内领先的企业级公有云服务商,致力于打造以数据为核心的场景化 PaaS 服务。围绕富媒体场景,七牛先后推出了对象存储,融合 CDN 加速,数据通用处理,内容反垃圾服务,以及直播云服务等。

    25 引用 • 217 回帖 • 163 关注
  • Log4j

    Log4j 是 Apache 开源的一款使用广泛的 Java 日志组件。

    20 引用 • 18 回帖 • 42 关注
  • flomo

    flomo 是新一代 「卡片笔记」 ,专注在碎片化时代,促进你的记录,帮你积累更多知识资产。

    3 引用 • 80 回帖
  • V2Ray
    1 引用 • 15 回帖
  • PWA

    PWA(Progressive Web App)是 Google 在 2015 年提出、2016 年 6 月开始推广的项目。它结合了一系列现代 Web 技术,在网页应用中实现和原生应用相近的用户体验。

    14 引用 • 69 回帖 • 131 关注
  • 链滴

    链滴是一个记录生活的地方。

    记录生活,连接点滴

    131 引用 • 3644 回帖
  • Netty

    Netty 是一个基于 NIO 的客户端-服务器编程框架,使用 Netty 可以让你快速、简单地开发出一个可维护、高性能的网络应用,例如实现了某种协议的客户、服务端应用。

    49 引用 • 33 回帖 • 23 关注