#新增索引库
PUT /heima
#查询索引库
GET /heima
#删除索引库
DELETE /heima
#创建映射
PUT /heima/_mapping
{
“properties”:{
“title”:{
“type”:“text”,
“analyzer”:“ik_smart”
},
“images”:{
“type”:“keyword”,
“index”:“false”
},
“price”:{
“type”:“float”
}
}
}
#创建索引库和映射
PUT /heima2
{
“mappings”: {
“properties”: {
“title”:{
“type”: “text”,
“analyzer”: “ik_max_word”
},
“images”:{
“type”: “keyword”,
“index”:“false”
},
“price”:{
“type”: “float”
}
}
}
}
#查看索引库的名称
GET /heima/_mapping
GET /heima2/_mapping
#新增文档
POST /heima/_doc
{
“title”:“小米手机”,
“images”:“http://image.leyou.con/11222.jpg”,
“price”:2699.00
}
#新增文档并指定id
POST /heima/_doc/2
{
“title”:“小米手机”,
“images”:“http://image.leyou.con/11222.jpg”,
“price”:2699.00
}
#查看文档
GET /heima/_doc/3
#修改文档
PUT /heima/_doc/1
{
“title”:“华为手机”,
“images”:“http://image.leyou.con/11222.jpg”,
“price”:2899.00
}
PUT /heima/_doc/3
{
“title”:“大米手机pro”,
“images”:“http://image.leuoi.jpg”,
“price”:3099.0
}
#删除文档
DELETE /heima/_doc/3
#新增未映射的字段
POST /heima/_doc/4
{
“title”:“超大幂手机”,
“images”:“http://leyou.com/12334”,
“price”:3999.00,
“stock”:200,
“saleable”:true,
“subtitle”:“超级双摄,以万像素”
}
#索引库的映射关系:
GET /heima
#动态模板
PUT heima03
{
“mappings”: {
“properties”: {
“title”: {
“type”: “text”,
“analyzer”: “ik_max_word”
}
},
“dynamic_templates”: [
{
“string”:{
“match_mapping_type”:“string”,
“mapping”:{
“type”:“keyworld”
}
}
}
]
}
}
#新增一条数据
POST /heima3/_doc/1
{
“title”:“超大米手机”,
“images”:“http://image.leyou.com/12479122.jpg”,
“price”:3299.00
}
#查看映射
GET /heima/_mapping
#插入两条数据
PUT /heima/_doc/5
{
“title”:“小米电视4A”,
“images”:“http://images.leyou.com/1111”,
“price”:3899.00
}
PUT /heima/_doc/6
{
“title”:“乐视电视4X”,
“images”:“http://images.leyou/1222”,
“price”:2499.00
}
#查询所有
GET /heima/_search
{
“query”:{
“match_all”: {}
}
}
#分词查询match
GET /heima/_search
{
“query”:{
“match”:{
“title”:“小米电视”
}
}
}
#精确查找,小米和电视
GET /heima/_search
{
“query”:{
“match”: {
“title”: {“query”:“小米电视”,“operator”: “and”}
}
}
}
GET /heima/_mapping
#词条匹配,查询的是一个词条,不会被分词
GET /heima/_search
{
“query”:{
“term”:{
“price”:2699.00
}
}
}
#fluzzy模糊查询
模糊查询 fuzzy
GET /heima/_search
{
“query”: {
“fuzzy”: {
“title”: {“value”: “小米”, “fuzziness”: 1}
}
}
}
#范围查询
GET /heima/_search
{
“query”: {
“range”: {
“price”: {
“gte”: 1000,
“lte”: 3000
}
}
}
}
#布尔查询
GET /heima/_search
{
“query”: {
“bool”: {
“must”: {
“match”: {
“title”: “小米”
}
},
"must_not": {
"match": {
"title": "电视"
}
}
}
}
}
#排序由
GET /heima/_search
{
“query”: {
“match”: {
“title”: “小米电视”
}
},
“sort”: [
{
“price”: {
“order”: “desc”
}
}
]
}
GET /heima/_search
{
“query”:{
“match”:{
“title”:“手机”
}
},
“highlight”: {
“pre_tags”: “”,
“post_tags”: “”,
“fields”: {
“title”: {}
}
}
}
GET /heima/_search
{
“query”: {
“match_all”: {}
},
“sort”: [
{
“price”: {
“order”: “asc”
}
}
],
“from”:0,
“size”: 20
}
#filter过滤
GET /heima/_search
{
“query”: {
“bool”: {
“must”: [
{
“match”: {
“title”: “小米手机”
}
},
{
“range”: {
“price”: {
“gte”: 2000,
“lte”: 3200
}
}
}
]
}
}
}
GET /heima/_search
{
“query”: {
“bool”: {
“must”: {
“match”: {
“title”: “小米手机”
}
},
“filter”: [
{
“range”:{
“price”:{
“gt”:2000,
“lt”:3200
}
}
}
]
}
}
}
#source 筛选
GET /heima/_search
{
“_source”: [“title”,“price”],
“query”: {
“term”: {
“price”: 2699
}
}
}
#指定includes和excludes
GET /heima/_search
{
“_source”: {
“includes”: [
“title”,
“price”
]
},
“query”: {
“term”: {
“price”: 2699
}
}
}
GET /heima/_search
{
“_source”: {
“excludes”: [“images”]
},
“query”: {
“term”: {
“price”: {
“value”: “2699”
}
}
}
}