ElasticSearch 기본 조회 1 (영어 분사)
12764 단어 ElasticSearch
PUT /lib3/user/1
{
"name" : "zhaoliu",
"address" :"hei long jiang sheng tie ling shi",
"age" : 50,
"birthday" : "1970-12-12",
"interests": "xi buan hejiu, duanlian, lvyou"
}
PUT /lib3/user/2
{
"name" :"zhaoming" ,
"address" : "bei jing hai dian qu qing he zhen",
"age" : 20,
"birthday" : "1998-10-12" ,
"interests": "xi huan hejiu, duanlian, changge"
}
PUT /lib3/user/3
{
"name" : "lisi",
"address" : "bei jing hai dian qu qing he zhen",
"age" : 23,
"birthday" : "1998-10-12" ,
"interests": "xi huan hejiu,duanlian, changge"
}
PUT /lib3/user/4
{
"name": "wangwu",
"address" : "bei jing hai dian qu qing he zhen",
"age": 26,
"birthday" : "1995-10-12" ,
"interests": "xi huan biancheng, tingyinyue, lvyou"
}
PUT /lib3/user/5
{
"name" :"zhangsan",
"address" : "bei jing chao yang qu",
"age" : 29,
"birthday" : "1988-10-12",
"interests": "xi huan tingyinyue , changge , tiaowu"
}
간단히 name를 통해 lisi라는 사람의 기본 정보를 찾습니다 GET/lib3/user/_search?q=name:lisi
{
"took" : 43,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "lib3",
"_type" : "user",
"_id" : "3",
"_score" : 0.2876821,
"_source" : {
"name" : "lisi",
"address" : "bei jing hai dian qu qing he zhen",
"age" : 23,
"birthday" : "1998-10-12",
"interests" : "xi huan hejiu,duanlian, changge"
}
}
]
}
}
이max_score: 관련 일치도 점수(ElasticSearch의 알고리즘에 따라 계산됨)
취미 조회 취미 interests changge(노래)를 좋아하는 사람, 그리고 나이 서열
GET /lib3/user/_search?q=interests:changge&sort=age:desc
{
"took" : 124,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : null,
"hits" : [
{
"_index" : "lib3",
"_type" : "user",
"_id" : "5",
"_score" : null,
"_source" : {
"name" : "zhangsan",
"address" : "bei jing chao yang qu",
"age" : 29,
"birthday" : "1988-10-12",
"interests" : "xi huan tingyinyue , changge , tiaowu"
},
"sort" : [
29
]
},
{
"_index" : "lib3",
"_type" : "user",
"_id" : "3",
"_score" : null,
"_source" : {
"name" : "lisi",
"address" : "bei jing hai dian qu qing he zhen",
"age" : 23,
"birthday" : "1998-10-12",
"interests" : "xi huan hejiu,duanlian, changge"
},
"sort" : [
23
]
},
{
"_index" : "lib3",
"_type" : "user",
"_id" : "2",
"_score" : null,
"_source" : {
"name" : "zhaoming",
"address" : "bei jing hai dian qu qing he zhen",
"age" : 20,
"birthday" : "1998-10-12",
"interests" : "xi huan hejiu, duanlian, changge"
},
"sort" : [
20
]
}
]
}
}
term과terms 조회 (zhaoliu라는 사람의 정보를 찾습니다)
termquery는 역삭궁 | 에서 정확한 term을 찾습니다. 분사기의 존재를 알지 못합니다.이런 검색은 키워드,numeric에 적합하다.date. term: 특정 필드에 키워드가 포함된 문서 검색 GET/lib3/user/_search/{"query": {interests":'changge'}}terms: 필드에 여러 키워드가 포함된 문서 GET/ib3/user/_search {"query": {"terms": {"interests": ["hejiu","changge"]}}}
GET /lib3/user/_search
{
"query": {
"term": {
"name": {
"value": "zhaoliu"
}
}
}
}
GET /lib3/user/_search
{
"query": {
"term": {
"name": "zhaoliu"
}
}
}
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "lib3",
"_type" : "user",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"name" : "zhaoliu",
"address" : "hei long jiang sheng tie ling shi",
"age" : 50,
"birthday" : "1970-12-12",
"interests" : "xi buan hejiu, duanlian, lvyou"
}
}
]
}
}
취미인interests가hejiuchangge인 사람 정보 찾기
GET /lib3/user/_search
{
"query": {
"terms": {
"interests": ["hejiu","changge"]
}
}
}
{
"took" : 56,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 4,
"max_score" : 1.0,
"hits" : [
{
"_index" : "lib3",
"_type" : "user",
"_id" : "5",
"_score" : 1.0,
"_source" : {
"name" : "zhangsan",
"address" : "bei jing chao yang qu",
"age" : 29,
"birthday" : "1988-10-12",
"interests" : "xi huan tingyinyue , changge , tiaowu"
}
},
{
"_index" : "lib3",
"_type" : "user",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"name" : "zhaoming",
"address" : "bei jing hai dian qu qing he zhen",
"age" : 20,
"birthday" : "1998-10-12",
"interests" : "xi huan hejiu, duanlian, changge"
}
},
{
"_index" : "lib3",
"_type" : "user",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"name" : "zhaoliu",
"address" : "hei long jiang sheng tie ling shi",
"age" : 50,
"birthday" : "1970-12-12",
"interests" : "xi buan hejiu, duanlian, lvyou"
}
},
{
"_index" : "lib3",
"_type" : "user",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"name" : "lisi",
"address" : "bei jing hai dian qu qing he zhen",
"age" : 23,
"birthday" : "1998-10-12",
"interests" : "xi huan hejiu,duanlian, changge"
}
}
]
}
}
키워드 하나만 있으면 다 조회가 돼요. 총 4명이서 Hejiu changge, changge, Hejiu, 둘 다 있어요.
from:0 (첫 번째 문서부터) size:2 (두 개의 문서를 가져오는 것)
GET /lib3/user/_search
{
"from":0,
"size":2,
"query": {
"terms": {
"interests": ["hejiu","changge"]
}
}
}
{
"took" : 81,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 4,
"max_score" : 1.0,
"hits" : [
{
"_index" : "lib3",
"_type" : "user",
"_id" : "5",
"_score" : 1.0,
"_source" : {
"name" : "zhangsan",
"address" : "bei jing chao yang qu",
"age" : 29,
"birthday" : "1988-10-12",
"interests" : "xi huan tingyinyue , changge , tiaowu"
}
},
{
"_index" : "lib3",
"_type" : "user",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"name" : "zhaoming",
"address" : "bei jing hai dian qu qing he zhen",
"age" : 20,
"birthday" : "1998-10-12",
"interests" : "xi huan hejiu, duanlian, changge"
}
}
]
}
}
이상의 조회는 버전 번호가 없습니다. 버전 번호를 얻으려면version:true 하나만 추가하십시오
GET /lib3/user/_search
{
"version": true,
"query": {
"terms": {
"interests": ["hejiu","changge"]
}
}
}
{
"took" : 33,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 4,
"max_score" : 1.0,
"hits" : [
{
"_index" : "lib3",
"_type" : "user",
"_id" : "5",
"_version" : 1,
"_score" : 1.0,
"_source" : {
"name" : "zhangsan",
"address" : "bei jing chao yang qu",
"age" : 29,
"birthday" : "1988-10-12",
"interests" : "xi huan tingyinyue , changge , tiaowu"
}
},
{
"_index" : "lib3",
"_type" : "user",
"_id" : "2",
"_version" : 1,
"_score" : 1.0,
"_source" : {
"name" : "zhaoming",
"address" : "bei jing hai dian qu qing he zhen",
"age" : 20,
"birthday" : "1998-10-12",
"interests" : "xi huan hejiu, duanlian, changge"
}
},
{
"_index" : "lib3",
"_type" : "user",
"_id" : "1",
"_version" : 1,
"_score" : 1.0,
"_source" : {
"name" : "zhaoliu",
"address" : "hei long jiang sheng tie ling shi",
"age" : 50,
"birthday" : "1970-12-12",
"interests" : "xi buan hejiu, duanlian, lvyou"
}
},
{
"_index" : "lib3",
"_type" : "user",
"_id" : "3",
"_version" : 1,
"_score" : 1.0,
"_source" : {
"name" : "lisi",
"address" : "bei jing hai dian qu qing he zhen",
"age" : 23,
"birthday" : "1998-10-12",
"interests" : "xi huan hejiu,duanlian, changge"
}
}
]
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
spring-data-elasticsearch 페이지 조회부록: 1. 이름에서 알 수 있듯이QueryBuilder는 검색 조건, 필터 조건을 구축하는 데 사용되고 SortBuilder는 정렬을 구축하는 데 사용된다. 예를 들어 우리는 어느 위치에서 100미터 범위 내의 모...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.