1.创建索引
put localhost:9200/person
2.添加数据
put localhost:9200/person/_doc/1
{
"first_name" : "John",
"last_name" : "Smith",
"age": 25,
"about" : "I love to go rock climbing",
"interests" : ["sports","music"]
}
3.搜索ES里面的数据
get localhost:9200/person/_doc/1
GET _all : 查看所有
GET /index名/_doc(默认的type,6版本以后可省略)/id : 根据id查
根据指定条件查询:
should=or
must=and
match=like
POST /person/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"last_name": "Smith"
}
},
{
"match": {
"about": "basketball"
}
}
]
}
}
}
启动logstash
bin/logstash -f config/mysql.conf
添加和更新文档
POST test/job/1
{
"becif": "612",
"uuid": "vprcBisp"
}
查询分词效果:
POST http://127.0.0.1:9200/_analyze?pretty=true
{
"analyzer":"standard",
"text": "我是程序员"
}
query string search
query DSL Domain Specified Language 特定领域的语言
GET ecommerce/product/_search
{
"query": {
"match_all": {}
}
}
GET /ecommerce/product/_search
{
"query": {
"match": {
"name": "yagao"
}
},
"sort": [
{
"price": {
"order": "desc"
}
}
]
}
_search 查询
#实现分页查询
GET ecommerce/product/_search
{
"query" :{"match_all":{}},
"from":1,
"size":2
}
GET ecommerce/product/_search
{
"query": {
"match_all": {}
},
"_source": ["name","price"]
}
3.query filter
搜索商品名称包含yagao,而且售价大于25的商品
GET /ecommerce/product/_search
{
"query": {
"bool": {
"must": {
"match":
{
"name":"yagao"
}
},
"filter": {
"range": {
"price": {
"gt": 25
}
}
}
}
}
}
4.全文检索
PUT /ecommerce/product/4
{
"name": "special yagao",
"desc": "special meibai",
"price": 50,
"producer": "special yagao producer",
"tags": [
"meibai"
]
}
GET /ecommerce/product/_search
{
"query": {
"match": {
"producer": "yagao producer"
}
}
}
无论学习什么技术,一定自己动手,特别是手工敲各种代码,不要粘贴复制,比如说当初学java,学shell, 学javascript,学hadoop
手机扫一扫
移动阅读更方便
你可能感兴趣的文章