From 3ac344153271082084d28a992e6f41577d02f166 Mon Sep 17 00:00:00 2001
From: blavenie <benoit.lavenier@e-is.pro>
Date: Tue, 21 Jun 2016 22:37:38 +0200
Subject: [PATCH]  - Fix market/record index : use attachement type for
 pictures  - market/record index : add 'thumbnail' property

---
 README.md                                     | 40 ++++++-----
 .../elasticsearch/node/DuniterNode.java       | 33 ++++++++-
 .../elasticsearch/service/MarketService.java  | 69 ++++++++++++++-----
 .../elasticsearch/threadpool/ThreadPool.java  | 22 ++++++
 4 files changed, 124 insertions(+), 40 deletions(-)

diff --git a/README.md b/README.md
index 45450e15..843c5929 100644
--- a/README.md
+++ b/README.md
@@ -14,22 +14,9 @@ duniter4j has four main components :
  - elasticsearch: a ES plugin, to store blockchain, registry, market and more.
     
 
-## Install
+## Install as ES plugin
 
- - Install ElasticSearch 2.3.3
- 
- - Install plugins :
- 
-   /bin/plugin install elastic/elasticsearch
-   
-   /bin/plugin install duniter/duniter4j
-
-
-## Test it
-
-
-
-The elasticsearch component is ready to use !
+### Install Java 
 
  - Install Java JRE 8 or more.
  
@@ -47,7 +34,22 @@ sudo apt-get install openjdk-8-jre
        exists on: /usr/local/lib or /opt/local/lib. If not, create a symbolic link.
        
     No installation need for Windows (include in binaries) 
-  
+
+### Install ElasticSearch 2.3.3
+
+ Download lastest release of ElasticSearch
+ 
+### Install ElasticSearch plugins
+ 
+   /bin/plugin install mapper-attachments
+   
+   /bin/plugin install https://github.com/duniter/duniter4j/releases/download/0.2.0/duniter4j-elasticsearch-0.2.0.zip
+
+
+## Install from standalone bundle 
+
+ - Installa Java (see on top) 
+ 
  - Download lastest release of file duniter4j-elasticsearch-X.Y-standalone.zip
  
  - Unzip, then start a elasticsearch node, just do :
@@ -58,7 +60,7 @@ cd duniter4j-elasticsearch-X.Y
 ./duniter4j-elasticsearch.sh start index -h <node_host> -p <node_port>
 ```
 
-Example on meta_brouzouf test currency :
+Example on test_net test currency :
 
 ```bash
 $ ./duniter4j-elasticsearch.sh start index -h  cgeek.fr -p 9330
@@ -101,7 +103,7 @@ Options:
 
 ```
 
-## Use it
+## Use API (Developer)
 
 When a blockchain currency has been indexed, you can test some fun queries :
 
@@ -157,7 +159,7 @@ More documentation here :
   - a good [tutorial](http://okfnlabs.org/blog/2013/07/01/elasticsearch-query-tutorial.html) 
 
 
-## Compile
+## Compile from source
  
  Install required dependencies:
  
diff --git a/duniter4j-elasticsearch/src/main/java/org/duniter/elasticsearch/node/DuniterNode.java b/duniter4j-elasticsearch/src/main/java/org/duniter/elasticsearch/node/DuniterNode.java
index 752f4c7c..d3ba09d2 100644
--- a/duniter4j-elasticsearch/src/main/java/org/duniter/elasticsearch/node/DuniterNode.java
+++ b/duniter4j-elasticsearch/src/main/java/org/duniter/elasticsearch/node/DuniterNode.java
@@ -1,5 +1,27 @@
 package org.duniter.elasticsearch.node;
 
+/*
+ * #%L
+ * Duniter4j :: ElasticSearch Plugin
+ * %%
+ * Copyright (C) 2014 - 2016 EIS
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the 
+ * License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public 
+ * License along with this program.  If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
 import org.duniter.core.client.model.local.Peer;
 import org.duniter.elasticsearch.PluginSettings;
 import org.duniter.elasticsearch.service.BlockchainService;
@@ -66,6 +88,10 @@ public class DuniterNode extends AbstractLifecycleComponent<DuniterNode> {
 
             injector.getInstance(BlockchainService.class)
                     .indexLastBlocks(peer);
+
+            if (logger.isInfoEnabled()) {
+                logger.info("Reloading all Duniter indices... [OK]");
+            }
         }
         else {
             if (logger.isInfoEnabled()) {
@@ -75,10 +101,11 @@ public class DuniterNode extends AbstractLifecycleComponent<DuniterNode> {
             injector.getInstance(RegistryService.class).createIndexIfNotExists();
 
             injector.getInstance(MarketService.class).createIndexIfNotExists();
-        }
 
-        if (logger.isInfoEnabled()) {
-            logger.info("Duniter indices created.");
+            if (logger.isInfoEnabled()) {
+                logger.info("Checking Duniter indices... [OK]");
+            }
         }
+
     }
 }
diff --git a/duniter4j-elasticsearch/src/main/java/org/duniter/elasticsearch/service/MarketService.java b/duniter4j-elasticsearch/src/main/java/org/duniter/elasticsearch/service/MarketService.java
index 1b9ea799..a7a78dc9 100644
--- a/duniter4j-elasticsearch/src/main/java/org/duniter/elasticsearch/service/MarketService.java
+++ b/duniter4j-elasticsearch/src/main/java/org/duniter/elasticsearch/service/MarketService.java
@@ -264,9 +264,14 @@ public class MarketService extends AbstractService {
                     .field("type", "double")
                     .endObject()
 
-                    // price Id UD
-                    .startObject("priceInUD")
-                    .field("type", "boolean")
+                    // price Unit
+                    .startObject("unit")
+                    .field("type", "string")
+                    .endObject()
+
+                    // currency
+                    .startObject("currency")
+                    .field("type", "string")
                     .endObject()
 
                     // issuer
@@ -285,24 +290,52 @@ public class MarketService extends AbstractService {
                     .field("type", "geo_point")
                     .endObject()
 
+                    // thumbnail
+                    .startObject("thumbnail")
+                    .field("type", "attachment")
+                        .startObject("fields") // src
+                        .startObject("content") // title
+                            .field("index", "no")
+                        .endObject()
+                        .startObject("title") // title
+                            .field("type", "string")
+                            .field("store", "no")
+                        .endObject()
+                        .startObject("author") // title
+                            .field("store", "no")
+                        .endObject()
+                        .startObject("content_type") // title
+                            .field("store", "yes")
+                        .endObject()
+                    .endObject()
+                    .endObject()
+
                     // pictures
                     .startObject("pictures")
                     .field("type", "nested")
-                    .startObject("properties")
-                    .startObject("src") // src
-                    // FISME : add attachment plugin
-                    //.field("type", "attachment")
-                    .field("type", "string")
-                    .field("index", "not_analyzed")
-                    .endObject()
-                    .startObject("title") // title
-                    .field("type", "string")
-                    .field("analyzer", stringAnalyzer)
-                    .startObject("norms") // disabled norms on title
-                    .field("enabled", "false")
-                    .endObject()
-                    .endObject()
-                    .endObject()
+                    .field("dynamic", "false")
+                        .startObject("properties")
+                            .startObject("file") // src
+                                .field("type", "attachment")
+                                .startObject("fields") // src
+                                    .startObject("content") // title
+                                        .field("index", "no")
+                                    .endObject()
+                                    .startObject("title") // title
+                                        .field("type", "string")
+                                        .field("store", "yes")
+                                        .field("analyzer", stringAnalyzer)
+                                    .endObject()
+                                    .startObject("author") // title
+                                        .field("type", "string")
+                                        .field("store", "no")
+                                    .endObject()
+                                    .startObject("content_type") // title
+                                        .field("store", "yes")
+                                    .endObject()
+                                .endObject()
+                            .endObject()
+                        .endObject()
                     .endObject()
 
                     // categories
diff --git a/duniter4j-elasticsearch/src/main/java/org/duniter/elasticsearch/threadpool/ThreadPool.java b/duniter4j-elasticsearch/src/main/java/org/duniter/elasticsearch/threadpool/ThreadPool.java
index 69aacc4b..8ca23af5 100644
--- a/duniter4j-elasticsearch/src/main/java/org/duniter/elasticsearch/threadpool/ThreadPool.java
+++ b/duniter4j-elasticsearch/src/main/java/org/duniter/elasticsearch/threadpool/ThreadPool.java
@@ -1,5 +1,27 @@
 package org.duniter.elasticsearch.threadpool;
 
+/*
+ * #%L
+ * Duniter4j :: ElasticSearch Plugin
+ * %%
+ * Copyright (C) 2014 - 2016 EIS
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the 
+ * License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public 
+ * License along with this program.  If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
 import com.google.common.collect.Lists;
 import org.elasticsearch.common.component.AbstractLifecycleComponent;
 import org.elasticsearch.common.component.Lifecycle;
-- 
GitLab