Elasticsearch(2)
1. 색인의 몇 가지 조회
1.query sting search
GET /ecummerce/product/_search
1.took :
2.timed_out
3._shards : , , primary shard( replica shard )
4.hits.total 3 document
5.hits.max_score :score document search , , 。
6.hits.hits: document
{
"took" : 438,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"name" : "jiajieshi yagao",
"desc" : "jiajieshi fangzhu",
"price" : 25,
"product" : "jiajieshi producter",
"tags" : [
"fengzhu"
]
}
},
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"name" : "zhonghua yagao",
"desc" : "caoben zhizu",
"price" : 40,
"product" : "zhonghua producter",
"tags" : [
"qingxin"
]
}
},
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"name" : "gaolujie yagao",
"desc" : "gaoxiao meibai",
"price" : 30,
"product" : "gaolujie producter",
"tags" : [
"fengzhu",
"meibai"
]
}
}
]
}
}
query string search r search http query string
2. yagao , :GET /ecommerce/product/_search?q=name:yagao&sort=price:desc
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "3",
"_score" : null,
"_source" : {
"name" : "zhonghua yagao",
"desc" : "caoben zhizu",
"price" : 40,
"product" : "zhonghua producter",
"tags" : [
"qingxin"
]
},
"sort" : [
40
]
},
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "1",
"_score" : null,
"_source" : {
"name" : "gaolujie yagao",
"desc" : "gaoxiao meibai",
"price" : 30,
"product" : "gaolujie producter",
"tags" : [
"fengzhu",
"meibai"
]
},
"sort" : [
30
]
},
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "2",
"_score" : null,
"_source" : {
"name" : "jiajieshi yagao",
"desc" : "jiajieshi fangzhu",
"price" : 25,
"product" : "jiajieshi producter",
"tags" : [
"fengzhu"
]
},
"sort" : [
25
]
}
]
}
}
query DSL
http equest body : json , , 。
:
GET /ecummerce/product/_search
{
"query":{
"match_all":{}
}
}
GET /ecummerce/product/_search
{
"query":{
"match_all":{}
}
}
G
yagao , ET /ecummerce/product/_search
{
"query":{
"match":{
"name":"yagao"
}
},
"sort":[
{"price":"desc"}
]
}
3. , 3 , 1 , 2 , 2
from:
size:
GET /ecummerce/product/_search
{
"query":{
"match_all":{}
},
"from":1,
"size":1
}
:
{
"took" : 32,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"name" : "zhonghua yagao",
"desc" : "caoben zhizu",
"price" : 40,
"product" : "zhonghua producter",
"tags" : [
"qingxin"
]
}
}
]
}
}
4.
GET /ecummerce/product/_search
{
"query":{
"match_all":{}
},
"_source":["name","price"]
}
{
"took" : 7,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"price" : 25,
"name" : "jiajieshi yagao"
}
},
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"price" : 40,
"name" : "zhonghua yagao"
}
},
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"price" : 30,
"name" : "gaolujie yagao"
}
}
]
}
}
3.query filter
yagao, 25
GET /ecummerce/product/_search
{
"query":{
"bool": {
"must": {
"match": {
"name": "yagao"
}
},
"filter":{
"range":{
"price":{
"gt":25
}
}
}
}
}
}
:
{
"took" : 35,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 0.13353139,
"hits" : [
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "3",
"_score" : 0.13353139,
"_source" : {
"name" : "zhonghua yagao",
"desc" : "caoben zhizu",
"price" : 40,
"product" : "zhonghua producter",
"tags" : [
"qingxin"
]
}
},
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "1",
"_score" : 0.13353139,
"_source" : {
"name" : "gaolujie yagao",
"desc" : "gaoxiao meibai",
"price" : 30,
"product" : "gaolujie producter",
"tags" : [
"fengzhu",
"meibai"
]
}
}
]
}
}
4.ful-text search ( )
GET /ecummerce/product/_search
{
"query":{
"match": {
"product": "yagao producter"
}
}
}
producter ,
:
{
"took" : 8,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 0.110377684,
"hits" : [
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "2",
"_score" : 0.110377684,
"_source" : {
"name" : "jiajieshi yagao",
"desc" : "jiajieshi fangzhu",
"price" : 25,
"product" : "jiajieshi producter",
"tags" : [
"fengzhu"
]
}
},
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "3",
"_score" : 0.110377684,
"_source" : {
"name" : "zhonghua yagao",
"desc" : "caoben zhizu",
"price" : 40,
"product" : "zhonghua producter",
"tags" : [
"qingxin"
]
}
},
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "1",
"_score" : 0.110377684,
"_source" : {
"name" : "gaolujie yagao",
"desc" : "gaoxiao meibai",
"price" : 30,
"product" : "gaolujie producter",
"tags" : [
"fengzhu",
"meibai"
]
}
},
{
"_index" : "ecummerce",
"_type" : "product",
"_id" : "5",
"_score" : 0.09271725,
"_source" : {
"name" : "special yagao",
"desc" : "special meibai",
"price" : 50,
"product" : "special gaolujie producter",
"tags" : [
"meibai"
]
}
}
]
}
}
5.highight search( )
6.
1. , tag
GET /ecummerce/product/_search
{
"aggs":{
"group_by_tages":{
"terms": {
"field": "tags"
}
}
}
}
PUT /ecummerce/_mapping/product
{
"properties":{
"tags":{
"type":"text",
"fielddata":true
}
}
}
: yagao , tag
GET /ecummerce/product/_search
{
"query":{
"match": {
"name": "yagao"
}
},
"aggs":{
"group_by_tages":{
"terms": {
"field": "tags"
}
}
}
}
, , , tag 。
GET /ecummerce/product/_search
{
"size":0,
"aggs":{
"group_by_tages":{
"terms": {
"field": "tags"
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Embulk를 사용하여 ElasticCloud로 보내기Embulk에서 ElasticCloud에 보낼 수 있을까라고 생각비망록도 겸해 기술을 남깁니다 Embulk 설치 ElasticCloud (14 일 체험판) brew라면 아래 명령 입력 파일 만들기 파일 내용 seed...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.