먼저 Cloud Search 서비스를 활성화합니다.
NHN Cloud Console에서 서비스 선택을 클릭합니다.
Cloud Search를 클릭합니다.
서비스가 활성화되었는지 확인하는 방법은 다음과 같습니다.
NHN Cloud Console 왼쪽 메뉴에서 Search를 클릭합니다.
Cloud Search가 보이면 서비스가 활성화된 것입니다.
서비스를 생성하는 방법은 다음과 같습니다.
서비스 생성 버튼을 클릭합니다.
서비스 생성 창에서 서비스 ID를 입력합니다.
저장 버튼을 클릭합니다.
생성된 서비스 결과를 확인합니다.
필드를 추가하는 방법은 다음과 같습니다.
필드 설정 탭을 클릭합니다.
필드 추가 버튼을 클릭합니다.
필드 이름을 입력합니다.
다중 값 사용 여부를 체크합니다.
색인 사용 여부를 체크합니다.
필터 사용 여부를 체크합니다.
정렬 사용 여부를 체크합니다.
요약 사용 여부를 체크합니다.
저장 버튼을 클릭합니다.
색인할 파일을 생성하고 색인하는 방법은 다음과 같습니다.
색인 파일 생성
[
{
"action": "add",
"id": "id-1",
"fields": {
"title": "[무료배송]나이키 슈즈 195종!!",
"body": "명불허전 나이키 인기슈즈 괜히 잘 팔리는게 아니죠~~ 나이키 핫!슈즈 195종★ 하나쯤은 있어야 하지 않아??"
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"title": "[슈퍼특가]나이키 운동화 109종",
"body": "단 7일만 이가격! [슈퍼특가] 아디다스 슈즈 109종 모음전 망설이면 품~절~"
}
},
{
"action": "add",
"id": "id-3",
"fields": {
"title": "[아디다스]신상운동화/슬리퍼 114종",
"body": "[아디다스슈즈모음♥] 무/료/배/송 [아디다스]신상슬리퍼 /슈퍼스타 스탠스미스 /튜블라외 114종 득템기회!"
}
}
]
색인 방법
색인 탭을 클릭합니다.
파일 선택 버튼을 클릭합니다.
색인할 파일을 선택합니다.
열기 버튼을 클릭합니다.
색인 명령어가 REST API로 출력됩니다.
색인 버튼을 클릭합니다.
색인 결과를 확인합니다.
REST API
아래와 같이 REST API를 사용 가능합니다.
curl -XPOST 'https://kr1-search.api.nhncloudservice.com/indexing/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/indexing' -H 'Accept-Language:ko' -H 'Content-Type:multipart/form-data; charset=UTF-8' -F 'file=@documents.json'
curl -XPOST 'https://kr1-search.api.nhncloudservice.com/indexing/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/indexing' -H 'Accept-Language:ko' -H 'Content-Type:application/json; charset=UTF-8' -d '
[
{
"action": "add",
"id": "id-1",
"fields": {
"title": "[무료배송]나이키 슈즈 195종!!",
"body": "명불허전 나이키 인기슈즈 괜히 잘 팔리는게 아니죠~~ 나이키 핫!슈즈 195종★ 하나쯤은 있어야 하지 않아??"
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"title": "[슈퍼특가]나이키 운동화 109종",
"body": "단 7일만 이가격! [슈퍼특가] 아디다스 슈즈 109종 모음전 망설이면 품~절~"
}
}
]'
{
"id": 1
}
curl -i -XGET 'https://kr1-search.api.nhncloudservice.com/indexing/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/indexing_log?id=1' -H 'Accept-Language:ko'
{
"request_time": "2017-10-23T12:36:43",
"file_name": "documents.json",
"file_size": 1185,
"status": 4
}
검색 방법은 다음과 같습니다.
검색 탭을 클릭합니다.
검색할 필드명을 체크합니다.
검색할 필드별 가중치를 설정합니다.
정렬할 필드를 선택합니다.
검색 결과에 출력할 필드를 체크합니다.
검색 결과 길이를 설정합니다.
강조(highlight) pre 태그를 설정합니다.
강조(highlight) post 태그를 설정합니다.
검색 결과에서 출력할 시작 순위를 지정합니다.
검색 결과 개수를 지정합니다.
검색 연산자를 선택합니다.
검색할 단어를 입력합니다.
검색 아이콘을 클릭합니다.
2~11번까지 설정한 내용이 REST API로 출력됩니다.
검색 결과가 출력됩니다.
REST API
아래와 같이 REST API를 사용할 수 있습니다.
curl -G -XGET 'https://kr1-search.api.nhncloudservice.com/search/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/search?start=1&size=10&q_option=and,body*1.0,title*1.0&return=&passage.body=180&passage.title=180' -H 'Accept-Language:ko' --data-urlencode q='나이키 운동화' --data-urlencode highlight='<b>,</b>' -H 'Accept-Language:ko'
{
"message": {
"meta": {
"timezone": "+09:00"
},
"result": {
"status": {
"code": 200,
"message": "OK"
},
"query": "나이키 운동화",
"start": 1,
"itemCount": 1,
"total": 1,
"itemList": {
"item": [
{
"_RELEVANCE": 100,
"_RANK": 1,
"_ID": "id-2",
"body": "단 7일만 이가격! [슈퍼특가] 아디다스 슈즈 109종 모음전 망설이품~절~",
"title": "[슈퍼특가]<b>나이키</b> <b>운동화</b> 109종"
}
]
}
}
}
통계를 확인하는 방법은 다음과 같습니다.
통계 탭을 클릭합니다.
전체 쿼리수 또는 결과 없는 쿼리수를 선택합니다.
시작 날짜를 입력합니다.
종료 날짜를 입력합니다.
조회 버튼을 클릭하면 통계 그래프가 출력됩니다.
데이터 다운로드를 클릭하면 쿼리별 통계 데이터가 다운로드됩니다.
전체 문서수 또는 전체 색인 사이즈를 선택합니다.
시작 날짜를 입력합니다.
종료 날짜를 입력합니다.
조회 버튼을 클릭하면 통계 그래프가 출력됩니다.
REST API
curl -i -XGET 'https://kr1-search.api.nhncloudservice.com/stats/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/stats?kind=total_query_count&date=2020-03-09' -H 'Accept-Language:ko'
[ [ "나이키", 8 ], [ "아디다스", 4 ] ]
색인 및 검색 REST API를 호출할 수 있는 장비의 IP를 제한할 수 있습니다.
ACL 설정 방법
아래는 IP 주소가 202.179.177.21인 경우에만 색인이 가능하고 검색 요청은 모든 IP에서 가능하도록 설정한 예입니다. 쿼리 통계 데이터 다운로드 요청은 모든 IP에서 가능하도록 설정한 예제입니다.
ACL 탭을 클릭합니다.
색인 아래 허용에 IP 주소를 입력합니다.
통계 허용에 'all'을 입력합니다.
검색 허용에 'all'을 입력합니다.
저장버튼을 클릭합니다.
필드를 삭제하는 방법은 다음과 같습니다.
삭제할 필드의 삭제 버튼을 클릭합니다.
저장 버튼을 클릭합니다.
지금 재색인 버튼을 클릭합니다.
필드 설정
색인
테스트를 위해 아래 데이터를 색인합니다.
[
{
"action": "add",
"id": "id-1",
"fields": {
"name": "나이키 에어맥스",
"category": 1
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"name": "나이키 샤이엔 솔리드",
"category": 2
}
}
]
검색
필터링 값 입력 방법입니다.
filter_or: 필터 필드 간 or 연산 필요시 사용합니다.
단일값 필터링
필드 설정
색인
테스트를 위해 아래 데이터를 색인합니다.
[
{
"action": "add",
"id": "id-1",
"fields": {
"name": "에프엑스수학학원",
"location": [10.1, 10.1]
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"name": "좋은나무 사고력수학학원",
"location": [10.3, 10.4]
}
},
{
"action": "add",
"id": "id-3",
"fields": {
"name": "수학의아침학원",
"location": [10.4, 10.3]
}
}
]
검색
필드 설정
다중 정렬 설정
색인
테스트를 위해 아래 데이터를 색인합니다.
[
{
"action": "add",
"id": "id-1",
"fields": {
"name": "나이키 에어맥스",
"popular": 10,
"price": 84180
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"name": "나이키 에어줌",
"popular": 5,
"price": 97200
}
},
{
"action": "add",
"id": "id-3",
"fields": {
"name": "나이키 에어포스",
"popular": 5,
"price": 74680
}
}
]
검색
정렬 필드를 선택 후 방식을 지정합니다.
다중 정렬 필드를 선택 후 방식을 지정합니다.
필드 설정
색인
테스트를 위해 아래 데이터를 색인합니다.
[
{
"action": "add",
"id": "id-1",
"fields": {
"name": "나이키 에어맥스",
"category": "신발"
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"name": "나이키 에어줌",
"category": "신발"
}
},
{
"action": "add",
"id": "id-3",
"fields": {
"name": "나이키 스우시 반팔티",
"category": "의류"
}
}
]
검색
요약 결과
"summary": {
"category": {
"신발": 2,
"의류": 1
}
}
필드 설정
색인
테스트를 위해 아래 데이터를 색인합니다.
[
{
"action": "add",
"id": "id-1",
"fields": {
"title": "나이키 신발"
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"title": "나이키 슈즈"
}
},
{
"action": "add",
"id": "id-3",
"fields": {
"title": "나이키 가방"
}
}
]
검색
'boolean'을 선택합니다.
&, |, (, ), ! 을 이용한 불리언 쿼리를 입력합니다.
검색
검색 결과
"itemList": {
"item": [
{
"_RELEVANCE": 200,
"_RANK": 1,
"_ID": "id-2",
"title": "<b>나이키</b>"
"body": "<b>나이키</b>"
},
{
"_RELEVANCE": 200,
"_RANK": 2,
"_ID": "id-1",
"title": "<b>나이키</b>"
"body": "<b>나이키</b>"
}
]
}
가중치 반영 비율 조정
curl -G -XGET 'https://kr1-search.api.nhncloudservice.com/search/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/search?start=1&size=10&q_option=and,title*1.0&return=&passage.title=180&doc_weight_ratio=0.1' --data-urlencode q='나이키' --data-urlencode highlight='<b>,</b>' -H 'Accept-Language:ko'
Tip
필드 설정
색인
테스트를 위해 아래 데이터를 색인합니다.
[
{
"action": "add",
"id": "id-1",
"ranking": 2,
"fields": {
"title": "나이키"
}
},
{
"action": "add",
"id": "id-2",
"ranking": 1,
"fields": {
"title": "나이키"
}
}
]
검색
검색 결과
"itemList": {
"item": [
{
"_RELEVANCE": 100,
"_RANK": 1,
"_ID": "id-2",
"title": "<b>나이키</b>"
},
{
"_RELEVANCE": 100,
"_RANK": 2,
"_ID": "id-1",
"title": "<b>나이키</b>"
}
]
}
설정 다운로드
설정 업로드
전체 데이터를 다시 색인할 때는 Full indexing API를 사용합니다.
curl -i -XPOST 'https://kr1-search.api.nhncloudservice.com/indexing/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/indexing/full/begin'
curl -XPOST 'https://kr1-search.api.nhncloudservice.com/indexing/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/indexing/full' -H 'Content-Type:multipart/form-data; charset=UTF-8' -F 'file=@documents-001.json'
curl -i -XPOST 'https://kr1-search.api.nhncloudservice.com/indexing/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/indexing/full/end'
curl -i -XPOST 'https://kr1-search.api.nhncloudservice.com/indexing/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/indexing/full/cancel'
URL
파라미터
형식 - 단어 사이를 콤마(',')로 구분. 단어 내에 공백 및 구분자 사용 불가
동의어
'신발' 검색
Request
curl -i -XPOST 'https://kr1-search.api.nhncloudservice.com/search/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/search?start=1&size=10&q_option=and,productName*1.0&return=productName&q=신발&passage.productName=180'
Response
"itemList": {
"item": [
{
"_ID": "100433865",
"_RANK": "0",
"_RELEVANCE": 100,
"productName": "부티크 리얼래빗퍼 슬리퍼 털슬리퍼 사무실<b>신발</b>"
}
]
}
동의어 사전 등록(단방향)
curl -i -XPOST 'https://kr1-search.api.nhncloudservice.com/dictionary/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/dictionary/thesaurus?way=1'
신발,운동화,스포츠화
'신발' 검색
Request
curl -i -XGET 'https://kr1-search.api.nhncloudservice.com/search/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/search?start=1&size=10&q_option=and,productName*1.0&return=productName&q=신발&passage.productName=180'
Response
"itemList": {
"item": [
{
"_ID": "100433865",
"_RANK": "0",
"_RELEVANCE": 100,
"productName": "부티크 리얼래빗퍼 슬리퍼 털슬리퍼 사무실<b>신발</b>"
},
{
"_ID": "101874425",
"_RANK": "0",
"_RELEVANCE": 1,
"productName": "아이보리도트운동화"
},
{
"_ID": "101714054",
"_RANK": "0",
"_RELEVANCE": 1,
"productName": "나이키/Nike Free TR 8 - Womens/Nike/기능성 스포츠화/라패셔니스타"
}
]
}
Request
curl -i -XGET 'https://kr1-search.api.nhncloudservice.com/search/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/search?start=1&size=10&q_option=and,productName*1.0&return=productName&q=운동화&passage.productName=180'
Response
"itemList": {
"item": [
{
"_ID": "101874425",
"_RANK": "0",
"_RELEVANCE": 100,
"productName": "아이보리도트<b>운동화</b>"
}
]
}
동의어 삭제(단방향)
curl -i -XDELETE 'https://kr1-search.api.nhncloudservice.com/dictionary/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/dictionary/thesaurus'
신발
Request
curl -i -XGET 'https://kr1-search.api.nhncloudservice.com/search/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/search?start=1&size=10&q_option=and,productName*1.0&return=productName&q=신발&passage.productName=180'
Response
"itemList": {
"item": [
{
"_ID": "100433865",
"_RANK": "0",
"_RELEVANCE": 100,
"productName": "부티크 리얼래빗퍼 슬리퍼 털슬리퍼 사무실<b>신발</b>"
}
]
}
'운동화' 검색
Request
curl -i -XGET 'https://kr1-search.api.nhncloudservice.com/search/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/search?start=1&size=10&q_option=and,productName*1.0&return=productName&q=운동화&passage.productName=180'
Response
"itemList": {
"item": [
{
"_ID": "101874425",
"_RANK": "0",
"_RELEVANCE": 100,
"productName": "아이보리도트<b>운동화</b>"
}
]
}
동의어 초기화
curl -i -XPOST 'https://kr1-search.api.nhncloudservice.com/dictionary/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/dictionary/thesaurus/reset'
URL
형식
불용어
'커피' 검색
Request
curl -i -XGET 'https://kr1-search.api.nhncloudservice.com/search/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/search?start=1&size=10&q_option=and,productName*1.0&return=productName&q=커피&passage.productName=180'
Response
"itemList": {
"item": [
{
"_ID": "100433702",
"_RANK": "0",
"_RELEVANCE": 100,
"productName": "(STANLEY) 스탠리 마운틴 <b>커피</b>시스템 500미리"
}
]
}
불용어 사전 등록
curl -i -XPOST 'https://kr1-search.api.nhncloudservice.com/dictionary/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/dictionary/stopwords'
커피
콜드브루
'커피' 검색
Request
curl -i -XGET 'https://kr1-search.api.nhncloudservice.com/search/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/search?start=1&size=10&q_option=and,productName*1.0&return=productName&q=커피&passage.productName=180'
Response
{
"message": {
"result": {
"total": 0,
"query": "커피",
"start": 1,
"status": {
"code": 200,
"message": "OK"
},
"itemCount": 0
},
"meta": {
"timezone": "+09:00"
}
}
}
'콜드브루' 검색
Request
curl -i -XGET 'https://kr1-search.api.nhncloudservice.com/search/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/search?start=1&size=10&q_option=and,productName*1.0&return=productName&q=콜드브루&passage.productName=180'
Response
{
"message": {
"result": {
"total": 0,
"query": "콜드브루",
"start": 1,
"status": {
"code": 200,
"message": "OK"
},
"itemCount": 0
},
"meta": {
"timezone": "+09:00"
}
}
}
불용어 사전 삭제
curl -i -XDELETE 'https://kr1-search.api.nhncloudservice.com/dictionary/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/dictionary/stopwords'
콜드브루
'콜드브루' 검색
Request
curl -i -XGET 'https://kr1-search.api.nhncloudservice.com/search/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/search?start=1&size=10&q_option=and,productName*1.0&return=productName&q=콜드브루&passage.productName=180'
Response
"itemList": {
"item": [
{
"_ID": "101704573",
"_RANK": "0",
"_RELEVANCE": 100,
"productName": "[블루빅센] 티모르레스떼 <b>콜드브루</b> 더치커피 750ml (고급형)"
}
]
}
불용어 사전 초기화
curl -i -XPOST 'https://kr1-search.api.nhncloudservice.com/dictionary/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/dictionary/stopwords/reset'
필드 타입 선택 화면은 다음과 같습니다.
형태소 분석기 선택 화면은 다음과 같습니다.
ACL 설정 화면은 다음과 같습니다.
다음은 파일 업로드 방식의 색인 예제 코드입니다.
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'
compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.6'
package com.toast.cloud.cloudsearch.client;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
public class IndexingClient {
public static void main(String[] args) throws IOException {
String documents = ""
+ "[\n"
+ " {\n"
+ " \"action\": \"add\",\n"
+ " \"id\": \"id-1\",\n"
+ " \"fields\": {\n"
+ " \"title\": \"[무료배송]나이키 슈즈 195종!!\",\n"
+ " \"body\": \"명불허전 나이키 인기슈즈 괜히 잘 팔리는게 아니죠~~ 나이키 핫!슈즈 195종★ 하나쯤은 있어야 하지 않아??\"\n"
+ " }\n"
+ " }\n"
+ "]";
File tempFile = File.createTempFile("documents-",".json", new File("/tmp/"));
tempFile.deleteOnExit();
PrintWriter printWriter = new PrintWriter(tempFile);
printWriter.println(documents);
printWriter.close();
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
// build multipart upload request.
HttpEntity data = MultipartEntityBuilder.create()
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
.addBinaryBody("file", tempFile, ContentType.DEFAULT_BINARY, tempFile.getName())
.build();
// build http request and assign multipart upload data.
HttpUriRequest request = RequestBuilder
.post("https://kr1-search.api.nhncloudservice.com/indexing/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/indexing")
.setEntity(data)
.build();
System.out.println("Executing request " + request.getRequestLine());
// Create a custom response handler.
ResponseHandler<String> responseHandler = response -> {
int status = response.getStatusLine().getStatusCode();
if (status >= 200 && status < 300) {
HttpEntity entity = response.getEntity();
return entity != null ? EntityUtils.toString(entity) : null;
} else {
throw new ClientProtocolException("Unexpected response status: " + status);
}
};
String responseBody = httpclient.execute(request, responseHandler);
System.out.println(responseBody);
}
}
}
<?php
$documents = ""
. "[\n"
. " {\n"
. " \"action\": \"add\",\n"
. " \"id\": \"id-1\",\n"
. " \"fields\": {\n"
. " \"title\": \"[무료배송]나이키 슈즈 195종!!\",\n"
. " \"body\": \"명불허전 나이키 인기슈즈 괜히 잘 팔리는게 아니죠~~ 나이키 핫!슈즈 195종★ 하나쯤은 있어야 하지 않아??\"\n"
. " }\n"
. " }\n"
. "]";
$file = DIRECTORY_SEPARATOR.trim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.ltrim("documents.json", DIRECTORY_SEPARATOR);
file_put_contents($file, $documents);
register_shutdown_function(function() use($file) {
unlink($file);
});
$data = array(
'file' => curl_file_create($file, "application/json", basename($file))
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://kr1-search.api.nhncloudservice.com/indexing/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/indexing");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data; charset=UTF-8"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$response = curl_exec($ch) or die(curl_error($ch));
print_r($response);
curl_close($ch);
?>