First, enable the Cloud Search Service.
Go to NHN Cloud Console and click Select Service.
Click Cloud Search.
Do as follows to check if service is enabled:
Click Search on the left menu on NHN Cloud Console.
If you can find Cloud Search, the service has been enabled.
Services can be created as follows:
Click Create Services.
Enter Service ID on Create Services.
Click Save.
Check the result of service creation.
Fields can be added as follows:
Click Set Fields.
Click Add Fields.
Enter field name.
Check whether to use multivalued.
Check whether to use index.
Check whether to use filter.
Check whether to use sorting.
Check whether to use summary.
Click Save.
Do as follows to create and index files.
Create Index Files
[
{
"action": "add",
"id": "id-1",
"fields": {
"title": "[Free Shipping] 195 types of Nike shoes!!",
"body":"The one and only Nike shoes are best selling for good reasons. Nike's 195 Hot-selling shoes★ Guess you need at least one pair of them??"
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"title": "[Super Low Prices]109 types of Nike shoes",
"body": "Just 7-day Opportunities! [Super Low Prices] for 109 types of Addidas shoes. Hesiation only pushes early sold-out"
}
},
{
"action": "add",
"id": "id-3",
"fields": {
"title": "[Addidas] 114 types of new sneakers/slides",
"body": "[Collection of Addidas Shoes ♥] Free Shipping [Addidas] Get 114 types of new slides/Superstar Stan Smith/Tubular and more!"
}
}
]
How to Indexing
Click Indexing.
Click Select File.
Select a file to indexing.
Click Open.
Indexing command comes as REST API.
Click Indexing.
Check indexing results.
REST API
REST APIs are available like below:
curl -XPOST 'https://kr1-search.api.nhncloudservice.com/indexing/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/indexing' -H 'Accept-Language:en' -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:en' -H 'Content-Type:application/json; charset=UTF-8' -d '
[
{
"action": "add",
"id": "id-1",
"fields": {
"title": "[Free Shipping] 195 types of Nike shoes!!",
"body": "The one and only Nike shoes are best selling for good reasons. Nike'\''s 195 Hot-selling shoes★ Guess you need at least one pair of them??"
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"title": "[Super Low Prices]109 types of Nike shoes",
"body": "Just 7-day Opportunities! [Super Low Prices] for 109 types of Addidas shoes. Hesiation only pushes early sold-out"
}
}
]'
{
"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:en'
{
"request_time" : "2017-10-23T12:36:43",
"file_name" : "documents.json",
"file_size" : 1185,
"status" : 4
}
Do as follows to search:
Click Search.
Check field name to search.
Set weighted value for each field to search.
Select a field to sort by.
Check a field for output on the search result.
Set the length of search result.
Set the highlighted pre tag.
Set the highlighted post tag.
Specify the priority order for an output from search result.
Specify the number of search results.
Select a search operator.
Enter a word to search.
Click a search icon.
Settings from 2 to 11 come as REST API.
The search result shows.
REST API
Use REST APIs as below:
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' --data-urlencode q='Nike shoes' --data-urlencode highlight='<b>,</b>' -H 'Accept-Language:en'
{
"message" : {
"meta" : {
"timezone" : "+09:00"
},
"result" : {
"status" : {
"code" : 200,
"message" : "OK"
},
"query" : "Nike shoes",
"start" : 1,
"itemCount" : 1,
"total" : 1,
"itemList" : {
"item" : [
{
"_RELEVANCE" : 100,
"_RANK" : 1,
"_ID" : "id-2",
"body" : "Prices for 109 types of Addidas <b>shoes</b>. Hesiation only pushes early",
"title" : "[Super Low Prices]<b>Nike</b> <b>shoes</b> 109 types"
}
]
}
}
}
Do as follows to check statistics:
Click Statistics.
Select Total Query Count or Query Count with No Results.
Enter start date.
Enter end date.
Click Query and statistical graph comes as output.
Click Download Data to download statistical data for each query.
Select Total Document Count or Total Index Size.
Enter start date.
Enter end date.
Click Query and statistical graph comes as output.
REST API
curl -i -XGET 'http://kr1-search.api.nhncloudservice.com/stats/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/stats?kind=total_query_count&date=2020-03-09' -H 'Accept-Language:en'
[ [ "Nike", 8 ], [ "Addidas", 4 ] ]
IPs may be restricted for equipment which may call index and search REST APIs.
How to Set ACL
The example regards to setting which allows indexing only when the IP address is 202.179.177.21, while search requests are available from all IPs.
Click ACL.
Enter IP address for Enable below Indexing.
Enter 'all' for Enable Statistics.
Enter 'all ' for Enable Search.
Click Save.
Do as follows to delete fields:
Click Delete for a field to delete.
Click Save.
Click Reindex now.
Set Fields
Indexing
To test, index request data as below:
[
{
"action": "add",
"id": "id-1",
"fields": {
"name" : "Nike Air Max",
"category" : 1
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"name" : "Nike Cheyenne Solid",
"category" : 2
}
}
]
Search
Enter filtering values like below:
filter_or: Used when OR operations between filter fields are required.
Single-value Filtering
Set Fields
Indexing
To test, index data as below:
[
{
"action": "add",
"id": "id-1",
"fields": {
"name" : "FX Math Academy",
"location" : [10.1, 10.1]
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"name" : "Tree Thinking Math Academy",
"location" : [10.3, 10.4]
}
},
{
"action": "add",
"id": "id-3",
"fields": {
"name" : "Morning of Math Academy",
"location" : [10.4, 10.3]
}
}
]
Search
Set Fields
Setting up multiple sorting
Indexing
To test, index data as below:
[
{
"action": "add",
"id": "id-1",
"fields": {
"name" : "Nike Air Max",
"popular" : 10,
"price" : 84180
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"name" : "Nike Air Zoom",
"popular" : 5,
"price" : 97200
}
},
{
"action": "add",
"id": "id-3",
"fields": {
"name" : "Nike Air Force",
"popular" : 5,
"price" : 74680
}
}
]
Search
Specify the sorting type.
Specify the sorting order.
Set Fields
Indexing
To test, index data as below:
[
{
"action": "add",
"id": "id-1",
"fields": {
"name" : "Nike Air Max",
"category" : "Shoes"
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"name" : "Nike Air Zoom",
"category" : "Shoes"
}
},
{
"action": "add",
"id": "id-3",
"fields": {
"name" : "Nike Swoosh short sleeve t-shirt",
"category" : "Clothing"
}
}
]
Search
Summary Result
"summary": {
"category": {
"신발": 2,
"의류": 1
}
}
Set Fields
Indexing
To test, index data as below:
[
{
"action": "add",
"id": "id-1",
"fields": {
"title" : "Nike Shoes"
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"title" : "Nike Shoes"
}
},
{
"action": "add",
"id": "id-3",
"fields": {
"title" : "Nike Bags"
}
}
]
Search
Select 'boolean'.
Enter boolean query by using &, |, (, ), or !.
Search
Search result
"itemList": {
"item": [
{
"_RELEVANCE": 200,
"_RANK": 1,
"_ID": "id-2",
"title": "<b>Nike</b>"
"body": "<b>Nike</b>"
},
{
"_RELEVANCE": 200,
"_RANK": 2,
"_ID": "id-1",
"title": "<b>Nike</b>"
"body": "<b>Nike</b>"
}
]
}
Adjust the weight ratio
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='Nike' --data-urlencode highlight='<b>,</b>' -H 'Accept-Language:en'
Tip
Set Fields
Indexing
To test, index data as below:
[
{
"action": "add",
"id": "id-1",
"ranking": 2,
"fields": {
"title" : "Nike"
}
},
{
"action": "add",
"id": "id-2",
"ranking": 1,
"fields": {
"title" : "Nike"
}
}
]
Search
Search Results
"itemList": {
"item": [
{
"_RELEVANCE": 100,
"_RANK": 1,
"_ID": "id-2",
"title": "<b>Nike</b>"
},
{
"_RELEVANCE": 100,
"_RANK": 2,
"_ID": "id-1",
"title": "<b>Nike</b>"
}
]
}
Download Setting
Upload Setting
To re-index the entire data, use Full Indexing API.
curl -i -XPOST 'http://kr1-search.api.nhncloudservice.com/indexing/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/indexing/full/begin'
curl -XPOST 'http://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 'http://kr1-search.api.nhncloudservice.com/indexing/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/indexing/full/end'
curl -i -XPOST 'http://kr1-search.api.nhncloudservice.com/indexing/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/indexing/full/cancel'
URL
Parameters
Format - Comma (',') separators between words. No spaces and delimiters within words
Synonyms
Search for ‘shoes’
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=shoes&passage.productName=180'
Response
"itemList": {
"item": [
{
"_ID": "100433865",
"_RANK": "0",
"_relevance": 100,
"productName": "Boutique Real Rabbitfur Slippers Fur Slippers Office<b>Shoes</b>"
}
]
}
Synonyms registration (one-way)
curl -i -XPOST 'https://kr1-search.api.nhncloudservice.com/dictionary/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/dictionary/thesaurus?way=1'
Shoes,Sneakers,Sports Shoes
Search for ‘shoes’
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": "Boutique Real Rabbitfur Slippers Fur Slippers Office<b>Shoes</b>"
},
{
"_ID": "101874425",
"_RANK": "0",
"_RELEVANCE": 1,
"productName": "ivorydot sneakers"
},
{
"_ID": "101714054",
"_RANK": "0",
"_RELEVANCE": 1,
"productName": "Nike/Nike Free TR 8 - Womens/Nike/Functional-Sneakers/Ladies"
}
]
}
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=sneakers&passage.productName=180'
Response
"itemList": {
"item": [
{
"_ID": "101874425",
"_RANK": "0",
"_relevance": 100,
"productName": "Ivory Dot<b>Sneakers</b>"
}
]
}
Delete synonyms (one-way)
curl -i -XDELETE 'https://kr1-search.api.nhncloudservice.com/dictionary/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/dictionary/thesaurus'
Shoes
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": "Boutique Real Rabbitfur Slippers Fur Slippers Office<b>Shoes</b>"
}
]
}
Search for ‘Sneakers’
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=sneakers&passage.productName=180'
Response
"itemList": {
"item": [
{
"_ID": "101874425",
"_RANK": "0",
"_relevance": 100,
"productName": "Ivory Dot<b>Sneakers</b>"
}
]
}
Reset synonyms
curl -i -XPOST 'https://kr1-search.api.nhncloudservice.com/dictionary/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/dictionary/thesaurus/reset'
URL
Format
Unused terms
Search for "coffee
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=coffee&passage.productName=180'
Response
"itemList": {
"item": [
{
"_ID": "100433702",
"_RANK": "0",
"_relevance": 100,
"productName": "(STANLEY) Stanley Mountain <b>Coffee</b> System 500 preview"
}
]
}
Register unused terms
curl -i -XPOST 'https://kr1-search.api.nhncloudservice.com/dictionary/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/dictionary/stopwords'
Coffee
Cold brew
Search for "coffee
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=coffee&passage.productName=180'
Response
{
"message": {
"result": {
"total": 0,
"query": "Coffee",
"start": 1,
"status": {
"code": 200,
"message": "OK"
},
"itemCount": 0
},
"meta": {
"timezone": "+09:00"
}
}
}
Search for ‘cold brew’
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=Coldbrew&passage.productName=180'
Response
{
"message": {
"result": {
"total": 0,
"query": "Cold brew",
"start": 1,
"status": {
"code": 200,
"message": "OK"
},
"itemCount": 0
},
"meta": {
"timezone": "+09:00"
}
}
}
Delete unused terms
curl -i -XDELETE 'https://kr1-search.api.nhncloudservice.com/dictionary/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/dictionary/stopwords'
Cold Brew
Search for ‘cold brew’
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=Coldbrew&passage.productName=180'
Response
"itemList": {
"item": [
{
"_ID": "101704573",
"_RANK": "0",
"_relevance": 100,
"productName": "[Blue Bixen] Timor Leste <b>Cold Brew</b> Dutch Coffee 750ml (Premium)"
}
]
}
Reset unused terms
curl -i -XPOST 'https://kr1-search.api.nhncloudservice.com/dictionary/v2.0/appkeys/CwSx6kv99g0QuNtM/serviceids/test/dictionary/stopwords/reset'
Field type can be selected like below.
Morpheme analyzer can be selected as below:
ACL can be set on the below page:
Following shows the file-uploading type index example codes.
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\": \"[Free Shipping]195 types of Nike shoes!!\",\n"
+ " \"body\": \"The one and only Nike shoes are best selling for good reasons. Nike's 195 Hot-selling shoes★ Guess you need at least one pair of them??"\"\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\": \"[Free Shipping]195 types of Nike shoes!!\",\n"
. " \"body\": \"The one and only Nike shoes are best selling for good reasons. Nike's 195 Hot-selling shoes★ Guess you need at least one pair of them??"\"\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);
?>