Skip to content
Snippets Groups Projects
Commit b4c3e508 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

- Add index type : registry/comment

parent 9603aed3
No related branches found
No related tags found
No related merge requests found
...@@ -295,6 +295,52 @@ public abstract class AbstractService implements Bean { ...@@ -295,6 +295,52 @@ public abstract class AbstractService implements Bean {
} }
} }
protected XContentBuilder createRecordCommentType(String index, String type) {
String stringAnalyzer = pluginSettings.getDefaultStringAnalyzer();
try {
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject(type)
.startObject("properties")
// issuer
.startObject("issuer")
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
// time
.startObject("time")
.field("type", "integer")
.endObject()
// message
.startObject("message")
.field("type", "string")
.field("analyzer", stringAnalyzer)
.endObject()
// record
.startObject("record")
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
// reply to
.startObject("reply_to")
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
.endObject()
.endObject().endObject();
return mapping;
}
catch(IOException ioe) {
throw new TechnicalException(String.format("Error while getting mapping for index [%s/%s]: %s", index, type, ioe.getMessage()), ioe);
}
}
public interface StringReaderHandler { public interface StringReaderHandler {
String onReadLine(String line); String onReadLine(String line);
......
...@@ -109,7 +109,7 @@ public class MarketService extends AbstractService { ...@@ -109,7 +109,7 @@ public class MarketService extends AbstractService {
createIndexRequestBuilder.setSettings(indexSettings); createIndexRequestBuilder.setSettings(indexSettings);
createIndexRequestBuilder.addMapping(RECORD_CATEGORY_TYPE, createRecordCategoryType()); createIndexRequestBuilder.addMapping(RECORD_CATEGORY_TYPE, createRecordCategoryType());
createIndexRequestBuilder.addMapping(RECORD_TYPE, createRecordType()); createIndexRequestBuilder.addMapping(RECORD_TYPE, createRecordType());
createIndexRequestBuilder.addMapping(RECORD_COMMENT_TYPE, createRecordCommentType()); createIndexRequestBuilder.addMapping(RECORD_COMMENT_TYPE, createRecordCommentType(INDEX, RECORD_COMMENT_TYPE));
createIndexRequestBuilder.execute().actionGet(); createIndexRequestBuilder.execute().actionGet();
return this; return this;
...@@ -371,18 +371,22 @@ public class MarketService extends AbstractService { ...@@ -371,18 +371,22 @@ public class MarketService extends AbstractService {
.field("type", "integer") .field("type", "integer")
.endObject() .endObject()
// categories // category
.startObject("categories") .startObject("category")
.field("type", "nested") .field("type", "nested")
.field("dynamic", "false")
.startObject("properties") .startObject("properties")
.startObject("cat1") // cat1 .startObject("id") // author
.field("type", "string") .field("type", "string")
.field("index", "not_analyzed") .field("index", "not_analyzed")
.endObject() .endObject()
.startObject("cat2") // cat2 .startObject("parent") // author
.field("type", "string") .field("type", "string")
.field("index", "not_analyzed") .field("index", "not_analyzed")
.endObject() .endObject()
.startObject("name") // author
.field("type", "string")
.endObject()
.endObject() .endObject()
.endObject() .endObject()
...@@ -404,50 +408,6 @@ public class MarketService extends AbstractService { ...@@ -404,50 +408,6 @@ public class MarketService extends AbstractService {
} }
} }
public XContentBuilder createRecordCommentType() {
String stringAnalyzer = pluginSettings.getDefaultStringAnalyzer();
try {
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject(RECORD_COMMENT_TYPE)
.startObject("properties")
// issuer
.startObject("issuer")
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
// time
.startObject("time")
.field("type", "integer")
.endObject()
// message
.startObject("message")
.field("type", "string")
.field("analyzer", stringAnalyzer)
.endObject()
// record
.startObject("record")
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
// reply to
.startObject("reply_to")
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
.endObject()
.endObject().endObject();
return mapping;
}
catch(IOException ioe) {
throw new TechnicalException(String.format("Error while getting mapping for index [%s/%s]: %s", INDEX, RECORD_COMMENT_TYPE, ioe.getMessage()), ioe);
}
}
} }
...@@ -74,6 +74,7 @@ public class RegistryService extends AbstractService { ...@@ -74,6 +74,7 @@ public class RegistryService extends AbstractService {
public static final String INDEX = "registry"; public static final String INDEX = "registry";
public static final String RECORD_TYPE = "record"; public static final String RECORD_TYPE = "record";
public static final String RECORD_CATEGORY_TYPE = "category"; public static final String RECORD_CATEGORY_TYPE = "category";
public static final String RECORD_COMMENT_TYPE = "comment";
public static final String CURRENCY_TYPE = "currency"; public static final String CURRENCY_TYPE = "currency";
private static final String CATEGORIES_BULK_CLASSPATH_FILE = "registry-categories-bulk-insert.json"; private static final String CATEGORIES_BULK_CLASSPATH_FILE = "registry-categories-bulk-insert.json";
...@@ -125,6 +126,7 @@ public class RegistryService extends AbstractService { ...@@ -125,6 +126,7 @@ public class RegistryService extends AbstractService {
createIndexRequestBuilder.addMapping(CURRENCY_TYPE, createCurrencyType()); createIndexRequestBuilder.addMapping(CURRENCY_TYPE, createCurrencyType());
createIndexRequestBuilder.addMapping(RECORD_CATEGORY_TYPE, createRecordCategoryType()); createIndexRequestBuilder.addMapping(RECORD_CATEGORY_TYPE, createRecordCategoryType());
createIndexRequestBuilder.addMapping(RECORD_TYPE, createRecordType()); createIndexRequestBuilder.addMapping(RECORD_TYPE, createRecordType());
createIndexRequestBuilder.addMapping(RECORD_COMMENT_TYPE, createRecordCommentType(INDEX, RECORD_COMMENT_TYPE));
createIndexRequestBuilder.execute().actionGet(); createIndexRequestBuilder.execute().actionGet();
return this; return this;
...@@ -394,8 +396,19 @@ public class RegistryService extends AbstractService { ...@@ -394,8 +396,19 @@ public class RegistryService extends AbstractService {
.field("index", "not_analyzed") .field("index", "not_analyzed")
.endObject() .endObject()
// location // pubkey
.startObject("location") .startObject("pubkey")
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
// address
.startObject("address")
.field("type", "string")
.endObject()
// city
.startObject("city")
.field("type", "string") .field("type", "string")
.endObject() .endObject()
...@@ -424,18 +437,55 @@ public class RegistryService extends AbstractService { ...@@ -424,18 +437,55 @@ public class RegistryService extends AbstractService {
.endObject() .endObject()
.endObject() .endObject()
// categories // pictures
.startObject("categories") .startObject("pictures")
.field("type", "nested")
.field("dynamic", "false")
.startObject("properties")
.startObject("file") // file
.field("type", "attachment")
.startObject("fields")
.startObject("content") // content
.field("index", "no")
.endObject()
.startObject("title") // title
.field("type", "string")
.field("store", "yes")
.field("analyzer", stringAnalyzer)
.endObject()
.startObject("author") // author
.field("type", "string")
.field("store", "no")
.endObject()
.startObject("content_type") // content_type
.field("store", "yes")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
// picturesCount
.startObject("picturesCount")
.field("type", "integer")
.endObject()
// category
.startObject("category")
.field("type", "nested") .field("type", "nested")
.field("dynamic", "false")
.startObject("properties") .startObject("properties")
.startObject("cat1") // cat1 .startObject("id") // author
.field("type", "string") .field("type", "string")
.field("index", "not_analyzed") .field("index", "not_analyzed")
.endObject() .endObject()
.startObject("cat2") // cat2 .startObject("parent") // author
.field("type", "string") .field("type", "string")
.field("index", "not_analyzed") .field("index", "not_analyzed")
.endObject() .endObject()
.startObject("name") // author
.field("type", "string")
.endObject()
.endObject() .endObject()
.endObject() .endObject()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment