学习 Elasticsearch 敲过的指令

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

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

相关帖子

欢迎来到这里!

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

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

推荐标签 标签

  • Vim

    Vim 是类 UNIX 系统文本编辑器 Vi 的加强版本,加入了更多特性来帮助编辑源代码。Vim 的部分增强功能包括文件比较(vimdiff)、语法高亮、全面的帮助系统、本地脚本(Vimscript)和便于选择的可视化模式。

    27 引用 • 66 回帖
  • Lute

    Lute 是一款结构化的 Markdown 引擎,支持 Go 和 JavaScript。

    25 引用 • 191 回帖 • 19 关注
  • 支付宝

    支付宝是全球领先的独立第三方支付平台,致力于为广大用户提供安全快速的电子支付/网上支付/安全支付/手机支付体验,及转账收款/水电煤缴费/信用卡还款/AA 收款等生活服务应用。

    29 引用 • 347 回帖 • 1 关注
  • 大数据

    大数据(big data)是指无法在一定时间范围内用常规软件工具进行捕捉、管理和处理的数据集合,是需要新处理模式才能具有更强的决策力、洞察发现力和流程优化能力的海量、高增长率和多样化的信息资产。

    89 引用 • 113 回帖
  • iOS

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

    84 引用 • 139 回帖 • 1 关注
  • 架构

    我们平时所说的“架构”主要是指软件架构,这是有关软件整体结构与组件的抽象描述,用于指导软件系统各个方面的设计。另外还有“业务架构”、“网络架构”、“硬件架构”等细分领域。

    139 引用 • 441 回帖
  • IDEA

    IDEA 全称 IntelliJ IDEA,是一款 Java 语言开发的集成环境,在业界被公认为最好的 Java 开发工具之一。IDEA 是 JetBrains 公司的产品,这家公司总部位于捷克共和国的首都布拉格,开发人员以严谨著称的东欧程序员为主。

    180 引用 • 400 回帖
  • ActiveMQ

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

    19 引用 • 13 回帖 • 628 关注
  • 一些有用的避坑指南。

    69 引用 • 93 回帖
  • Dubbo

    Dubbo 是一个分布式服务框架,致力于提供高性能和透明化的 RPC 远程服务调用方案,是 [阿里巴巴] SOA 服务化治理方案的核心框架,每天为 2,000+ 个服务提供 3,000,000,000+ 次访问量支持,并被广泛应用于阿里巴巴集团的各成员站点。

    60 引用 • 82 回帖 • 601 关注
  • 单点登录

    单点登录(Single Sign On)是目前比较流行的企业业务整合的解决方案之一。SSO 的定义是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统。

    9 引用 • 25 回帖 • 3 关注
  • Webswing

    Webswing 是一个能将任何 Swing 应用通过纯 HTML5 运行在浏览器中的 Web 服务器,详细介绍请看 将 Java Swing 应用变成 Web 应用

    1 引用 • 15 回帖 • 634 关注
  • Google

    Google(Google Inc.,NASDAQ:GOOG)是一家美国上市公司(公有股份公司),于 1998 年 9 月 7 日以私有股份公司的形式创立,设计并管理一个互联网搜索引擎。Google 公司的总部称作“Googleplex”,它位于加利福尼亚山景城。Google 目前被公认为是全球规模最大的搜索引擎,它提供了简单易用的免费服务。不作恶(Don't be evil)是谷歌公司的一项非正式的公司口号。

    49 引用 • 192 回帖
  • JSON

    JSON (JavaScript Object Notation)是一种轻量级的数据交换格式。易于人类阅读和编写。同时也易于机器解析和生成。

    51 引用 • 190 回帖 • 2 关注
  • 负能量

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

    85 引用 • 1201 回帖 • 454 关注
  • HTML

    HTML5 是 HTML 下一个的主要修订版本,现在仍处于发展阶段。广义论及 HTML5 时,实际指的是包括 HTML、CSS 和 JavaScript 在内的一套技术组合。

    103 引用 • 294 回帖 • 3 关注
  • RabbitMQ

    RabbitMQ 是一个开源的 AMQP 实现,服务器端用 Erlang 语言编写,支持多种语言客户端,如:Python、Ruby、.NET、Java、C、PHP、ActionScript 等。用于在分布式系统中存储转发消息,在易用性、扩展性、高可用性等方面表现不俗。

    49 引用 • 60 回帖 • 392 关注
  • MySQL

    MySQL 是一个关系型数据库管理系统,由瑞典 MySQL AB 公司开发,目前属于 Oracle 公司。MySQL 是最流行的关系型数据库管理系统之一。

    675 引用 • 535 回帖
  • Unity

    Unity 是由 Unity Technologies 开发的一个让开发者可以轻松创建诸如 2D、3D 多平台的综合型游戏开发工具,是一个全面整合的专业游戏引擎。

    25 引用 • 7 回帖 • 250 关注
  • CodeMirror
    1 引用 • 2 回帖 • 114 关注
  • VirtualBox

    VirtualBox 是一款开源虚拟机软件,最早由德国 Innotek 公司开发,由 Sun Microsystems 公司出品的软件,使用 Qt 编写,在 Sun 被 Oracle 收购后正式更名成 Oracle VM VirtualBox。

    10 引用 • 2 回帖 • 6 关注
  • 域名

    域名(Domain Name),简称域名、网域,是由一串用点分隔的名字组成的 Internet 上某一台计算机或计算机组的名称,用于在数据传输时标识计算机的电子方位(有时也指地理位置)。

    43 引用 • 208 回帖
  • golang

    Go 语言是 Google 推出的一种全新的编程语言,可以在不损失应用程序性能的情况下降低代码的复杂性。谷歌首席软件工程师罗布派克(Rob Pike)说:我们之所以开发 Go,是因为过去 10 多年间软件开发的难度令人沮丧。Go 是谷歌 2009 发布的第二款编程语言。

    491 引用 • 1383 回帖 • 373 关注
  • 阿里巴巴

    阿里巴巴网络技术有限公司(简称:阿里巴巴集团)是以曾担任英语教师的马云为首的 18 人,于 1999 年在中国杭州创立,他们相信互联网能够创造公平的竞争环境,让小企业通过创新与科技扩展业务,并在参与国内或全球市场竞争时处于更有利的位置。

    43 引用 • 221 回帖 • 243 关注
  • flomo

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

    3 引用 • 80 回帖 • 1 关注
  • webpack

    webpack 是一个用于前端开发的模块加载器和打包工具,它能把各种资源,例如 JS、CSS(less/sass)、图片等都作为模块来使用和处理。

    41 引用 • 130 回帖 • 297 关注
  • wolai

    我来 wolai:不仅仅是未来的云端笔记!

    1 引用 • 11 回帖 • 1 关注