索引的创建,更新,删除
PUT / emloyee
{
"settings" : {
"numbers_of_shards" : 1 ,
"numbers_of_replicas" : 1
}
}
PUT / employee/ _doc/ 1
{
"name" : "张三" ,
"age" : 30
}
{
"_index" : "employee" ,
"_type" : "_doc" ,
"_id" : "1" ,
"_version" : 1 ,
"result" : "created" ,
"_shards" : {
"total" : 2 ,
"successful" : 2 ,
"failed" : 0
} ,
"_seq_no" : 0 ,
"_primary_term" : 1
}
PUT / employee/ _doc/ 1
{
"name" : "张三2" ,
"age" : 30
}
{
"_index" : "employee" ,
"_type" : "_doc" ,
"_id" : "1" ,
"_version" : 2 ,
"result" : "updated" ,
"_shards" : {
"total" : 2 ,
"successful" : 2 ,
"failed" : 0
} ,
"_seq_no" : 2 ,
"_primary_term" : 1
}
GET / employee/ _doc/ 1
{
"_index" : "employee" ,
"_type" : "_doc" ,
"_id" : "1" ,
"_version" : 2 ,
"_seq_no" : 2 ,
"_primary_term" : 1 ,
"found" : true ,
"_sourse" : {
"name" : "张三2" ,
"age" : 30
}
}
POST / employee/ _update/ 1
{
"doc" : {
"name" : "张三三"
}
}
POST / employee/ _create/ 2
{
"name" : "123" ,
"age" : 30
}
DELETE / employee/ _doc/ 2
GET / employee/ _search
PUT / emloyee
{
"settings" : {
"numbers_of_shards" : 1 ,
"numbers_of_replicas" : 1
} ,
"mappings" : {
"properties" : {
"name" : { "type" : "text" } ,
"age" : { "type" : "integer" }
}
}
}
POST / employee/ _create/ 2
{
"name" : "123" ,
"age" : "字符串测试"
"gender" : "男"
}
索引简单查询
GET / employee/ _search
{
"query" : {
"match_all" : { }
}
}
GET / employee/ _search
{
"query" : {
"match_all" : { }
} ,
"from" : 0 ,
"to" : 1
}
GET / employee/ _search
{
"query" : {
"match" : {
"name" : "兄弟"
}
}
}
GET / employee/ _search
{
"query" : {
"match" : {
"name" : "兄弟"
}
} ,
"sort" : [
{ "age" : { "order" : "desc" } }
]
}
GET / employee/ _search
{
"query" : {
"bool" : {
"filter" : [
{ "term" : { "name" : "张" } }
]
}
}
}
GET / employee/ _search
{
"query" : {
"match" : {
"name" : "兄"
}
} ,
"sort" : [
{ "age" : { "order" : "desc" } }
] ,
"aggs" : {
"group_by_age" : {
"terms" : {
"field" : "age"
}
}
}
}
analyze分析过程
PUT / movie/ _doc
{
"name" : "Eating an apple a day"
}
GET / movie/ _analyze
{
"field" : "name" ,
"text" : "Eating an apple a day"
}
analyze分析过程:字符过滤器 -> 字符处理(标准字符处理,以空格和标点符号分割内容) -> 分词过滤(分词转换,即变小写)
PUT / movie
{
"settings" : {
"numbers_of_shards" : 1 ,
"numbers_of_replicas" : 1
} ,
"mappings" : {
"properties" : {
"name" : { "type" : "text" , "analyzer" : "english" }
}
}
}
PUT / movie/ _doc
{
"name" : "Eating an apple a day"
}
english analyze分析过程:字符过滤器(过滤特殊符号,外加量词,the等等) -> 字符处理(标准字符处理,以空格和标点符号分割内容) -> 分词过滤(分词转换,词干转化,比如去除复数(apples/apple -> appl,daies/day -> dai))
类型
Text:被分析索引的字符串类型 Keyword:不能被分析只能被精确匹配的字符串类型 Date:日期类型,可以配合format一起使用 数字类型:long,integer,short,double等 boolean:true/false 数组类型:Array:[“one”, “two”] Object类型:json嵌套 Ip类型 Geo_point:地理位置