Skip to content

Commit

Permalink
re
Browse files Browse the repository at this point in the history
  • Loading branch information
gitchennan committed Mar 30, 2017
1 parent b57cdd9 commit 8d7443d
Show file tree
Hide file tree
Showing 37 changed files with 934 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ SearchResponse response = searchReq.execute().actionGet();
## 二、集成MyBatis、Spring
首先在Spring配置文件中增加如下代码
1. 指定driverClassName:org.elasticsearch.jdbc.api.ElasticDriver
2. 指定连接ES的连接串:jdbc:elastic:172.19.22.34:9300/product_cluster
2. 指定连接ES的连接串:jdbc:elastic:192.168.0.109:9300/product_cluster
3. 创建一个SqlMapClient对象,并指定sqlMapConfig.xml路径
```bash
<bean id="elasticDataSource" class="org.elasticsearch.jdbc.api.ElasticSingleConnectionDataSource" destroy-method="destroy">
<property name="driverClassName" value="org.elasticsearch.jdbc.api.ElasticDriver" />
<property name="url" value="jdbc:elastic:172.19.22.34:9300/product_cluster" />
<property name="url" value="jdbc:elastic:192.168.0.109:9300/product_cluster" />
</bean>

<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
Expand Down
10 changes: 5 additions & 5 deletions create_index.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
curl -XDELETE 'http://172.19.22.34:9200/index/'
curl -XDELETE 'http://192.168.0.109:9200/index/'

curl -XPUT 'http://172.19.22.34:9200/index/' -d '{
curl -XPUT 'http://192.168.0.109:9200/index/' -d '{
"settings": {
"index": {
"number_of_shards": 1,
Expand Down Expand Up @@ -55,7 +55,7 @@ curl -XPUT 'http://172.19.22.34:9200/index/' -d '{
}'


curl -XPUT 'http://172.19.22.34:9200/index/product/1' -d '{
curl -XPUT 'http://192.168.0.109:9200/index/product/1' -d '{
"productName" : "iphone 6s",
"productCode" : "IP_6S",
"minPrice" : 2288.00,
Expand All @@ -78,7 +78,7 @@ curl -XPUT 'http://172.19.22.34:9200/index/product/1' -d '{
}]
}'

curl -XPUT 'http://172.19.22.34:9200/index/product/2' -d '{
curl -XPUT 'http://192.168.0.109:9200/index/product/2' -d '{
"productName" : "apple watch os2",
"productCode" : "AW_OS2",
"minPrice" : 1000.00,
Expand All @@ -101,4 +101,4 @@ curl -XPUT 'http://172.19.22.34:9200/index/product/2' -d '{
}]
}'

curl -XPOST 'http://172.19.22.34:9200/index/_refresh'
curl -XPOST 'http://192.168.0.109:9200/index/_refresh'
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public AbstractAtomMethodQueryParser(ParseActionListener parseActionListener) {

protected abstract AtomQuery parseMethodQueryExpr(SQLMethodInvokeExpr matchQueryExpr, String queryAs, Object[] sqlArgs);

protected interface IConditionMethodQueryBuilder {
QueryBuilder buildQuery(String queryFieldName, Object[] parameters);
}


public final AtomQuery parseAtomMethodQuery(SQLMethodInvokeExpr methodQueryExpr, String queryAs, Object[] sqlArgs) {
checkQueryMethod(methodQueryExpr, queryAs, sqlArgs);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//package org.elasticsearch.dsl.parser.query.method;
//
//import com.alibaba.druid.sql.ast.SQLExpr;
//import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
//import com.google.common.collect.Maps;
//import org.elasticsearch.dsl.bean.AtomQuery;
//import org.elasticsearch.dsl.bean.ElasticSqlQueryField;
//import org.elasticsearch.dsl.enums.QueryFieldType;
//import org.elasticsearch.dsl.exception.ElasticSql2DslException;
//import org.elasticsearch.dsl.listener.ParseActionListener;
//import org.elasticsearch.dsl.parser.sql.QueryFieldParser;
//import org.elasticsearch.index.query.QueryBuilder;
//
//import java.util.Map;
//
//public abstract class AbstractFieldSpecifiedMethodQueryParser extends CheckableMethodQueryParser {
//
// protected static final String COMMA = ",";
//
// protected static final String COLON = ":";
//
// protected ParseActionListener parseActionListener;
//
// public AbstractFieldSpecifiedMethodQueryParser(ParseActionListener parseActionListener) {
// this.parseActionListener = parseActionListener;
// }
//
// protected abstract void checkQueryMethod(SQLMethodInvokeExpr matchQueryExpr, String queryAs, Object[] sqlArgs);
//
// protected abstract AtomQuery parseMethodQueryExpr(SQLMethodInvokeExpr matchQueryExpr, String queryAs, Object[] sqlArgs);
//
// protected interface IConditionMethodQueryBuilder {
// QueryBuilder buildQuery(String queryFieldName, Object[] parameters);
// }
//
//
// public final AtomQuery parseAtomMethodQuery(SQLMethodInvokeExpr methodQueryExpr, String queryAs, Object[] sqlArgs) {
// checkQueryMethod(methodQueryExpr, queryAs, sqlArgs);
//
// return parseMethodQueryExpr(methodQueryExpr, queryAs, sqlArgs);
// }
//
// protected AtomQuery parseCondition(SQLExpr queryFieldExpr, Object[] parameters, String queryAs, IConditionMethodQueryBuilder queryBuilder) {
// QueryFieldParser queryFieldParser = new QueryFieldParser();
// ElasticSqlQueryField queryField = queryFieldParser.parseConditionQueryField(queryFieldExpr, queryAs);
//
// AtomQuery atomQuery = null;
// if (queryField.getQueryFieldType() == QueryFieldType.RootDocField || queryField.getQueryFieldType() == QueryFieldType.InnerDocField) {
// QueryBuilder originalQuery = queryBuilder.buildQuery(queryField.getQueryFieldFullName(), parameters);
// atomQuery = new AtomQuery(originalQuery);
// }
//
// if (queryField.getQueryFieldType() == QueryFieldType.NestedDocField) {
// QueryBuilder originalQuery = queryBuilder.buildQuery(queryField.getQueryFieldFullName(), parameters);
// atomQuery = new AtomQuery(originalQuery, queryField.getNestedDocContextPath());
// }
//
// if (atomQuery == null) {
// throw new ElasticSql2DslException(String.format("[syntax error] query condition field can not support type[%s]", queryField.getQueryFieldType()));
// }
//
// onAtomMethodQueryConditionParse(queryField, parameters);
//
// return atomQuery;
// }
//
// private void onAtomMethodQueryConditionParse(ElasticSqlQueryField paramName, Object[] parameters) {
// try {
// parseActionListener.onAtomMethodQueryConditionParse(paramName, parameters);
// }
// catch (Exception ex) {
// try {
// parseActionListener.onFailure(ex);
// }
// catch (Exception exp) {
// //ignore;
// }
// }
// }
//
// protected Map<String, String> buildExtraMethodQueryParamsMap(String strMatchQueryParams) {
// Map<String, String> extraParamMap = Maps.newHashMap();
// for (String paramPair : strMatchQueryParams.split(COMMA)) {
// String[] paramPairArr = paramPair.split(COLON);
// if (paramPairArr.length == 2) {
// extraParamMap.put(paramPairArr[0].trim(), paramPairArr[1].trim());
// }
// else {
// throw new ElasticSql2DslException("Failed to parse query method params!");
// }
// }
// return extraParamMap;
// }
//
// protected Boolean isExtraParamsString(String extraParams) {
// for (String paramPair : extraParams.split(COMMA)) {
// String[] paramPairArr = paramPair.split(COLON);
// if (paramPairArr.length != 2) {
// return Boolean.FALSE;
// }
// }
// return Boolean.TRUE;
// }
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.elasticsearch.dsl.parser.query.method;

import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
import org.elasticsearch.dsl.bean.AtomQuery;
import org.elasticsearch.dsl.exception.ElasticSql2DslException;

public abstract class CheckableMethodQueryParser implements MethodQueryParser {

abstract void checkQueryMethod(SQLMethodInvokeExpr matchQueryExpr, String queryAs, Object[] sqlArgs);

abstract AtomQuery parseMethodQueryExpr(SQLMethodInvokeExpr matchQueryExpr, String queryAs, Object[] sqlArgs);

@Override
public AtomQuery parseAtomMethodQuery(SQLMethodInvokeExpr methodExpr, String queryAs, Object[] sqlArgs) throws ElasticSql2DslException {
checkQueryMethod(methodExpr, queryAs, sqlArgs);
return parseMethodQueryExpr(methodExpr, queryAs, sqlArgs);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.elasticsearch.dsl.parser.query.method;

import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
import org.elasticsearch.dsl.bean.AtomQuery;
import org.elasticsearch.dsl.exception.ElasticSql2DslException;

public interface MethodQueryParser {

boolean isMethodOf(SQLMethodInvokeExpr methodExpr);

AtomQuery parseAtomMethodQuery(SQLMethodInvokeExpr methodExpr, String queryAs, Object[] sqlArgs) throws ElasticSql2DslException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
import org.elasticsearch.dsl.listener.ParseActionListener;
import org.elasticsearch.dsl.parser.query.method.AbstractAtomMethodQueryParser;
import org.elasticsearch.dsl.parser.query.method.IConditionMethodQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
import org.elasticsearch.dsl.listener.ParseActionListener;
import org.elasticsearch.dsl.parser.query.method.AbstractAtomMethodQueryParser;
import org.elasticsearch.dsl.parser.query.method.IConditionMethodQueryBuilder;
import org.elasticsearch.index.query.FuzzyQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
import org.elasticsearch.dsl.listener.ParseActionListener;
import org.elasticsearch.dsl.parser.query.method.AbstractAtomMethodQueryParser;
import org.elasticsearch.dsl.parser.query.method.IConditionMethodQueryBuilder;
import org.elasticsearch.index.query.PrefixQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
import org.elasticsearch.dsl.listener.ParseActionListener;
import org.elasticsearch.dsl.parser.query.method.AbstractAtomMethodQueryParser;
import org.elasticsearch.dsl.parser.query.method.IConditionMethodQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RegexpFlag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
import org.elasticsearch.dsl.listener.ParseActionListener;
import org.elasticsearch.dsl.parser.query.method.AbstractAtomMethodQueryParser;
import org.elasticsearch.dsl.parser.query.method.IConditionMethodQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.TermQueryBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
import org.elasticsearch.dsl.listener.ParseActionListener;
import org.elasticsearch.dsl.parser.query.method.AbstractAtomMethodQueryParser;
import org.elasticsearch.dsl.parser.query.method.IConditionMethodQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.TermsQueryBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
import org.elasticsearch.dsl.listener.ParseActionListener;
import org.elasticsearch.dsl.parser.query.method.AbstractAtomMethodQueryParser;
import org.elasticsearch.dsl.parser.query.method.IConditionMethodQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.WildcardQueryBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="3" failures="0" name="org.elasticsearch.query.SqlParserLimitTest" time="1.457" errors="0" skipped="0">
<properties>
<property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
<property name="sun.boot.library.path" value="E:\dev\Java\jdk1.8.0_66\jre\bin"/>
<property name="java.vm.version" value="25.66-b18"/>
<property name="java.vm.vendor" value="Oracle Corporation"/>
<property name="maven.multiModuleProjectDirectory" value="E:/dev/work/elasticsearch-query-toolkit"/>
<property name="java.vendor.url" value="http://java.oracle.com/"/>
<property name="path.separator" value=";"/>
<property name="guice.disable.misplaced.annotation.check" value="true"/>
<property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM"/>
<property name="file.encoding.pkg" value="sun.io"/>
<property name="user.script" value=""/>
<property name="user.country" value="CN"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="sun.os.patch.level" value="Service Pack 1"/>
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="user.dir" value="E:\dev\work\elasticsearch-query-toolkit"/>
<property name="java.runtime.version" value="1.8.0_66-b18"/>
<property name="java.awt.graphicsenv" value="sun.awt.Win32GraphicsEnvironment"/>
<property name="java.endorsed.dirs" value="E:\dev\Java\jdk1.8.0_66\jre\lib\endorsed"/>
<property name="os.arch" value="amd64"/>
<property name="java.io.tmpdir" value="C:\Users\chennan\AppData\Local\Temp\"/>
<property name="line.separator" value="
"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="user.variant" value=""/>
<property name="os.name" value="Windows 7"/>
<property name="classworlds.conf" value="E:/dev/apache-maven-3.3.9/bin/m2.conf"/>
<property name="sun.jnu.encoding" value="GBK"/>
<property name="java.library.path" value="E:\dev\Java\jdk1.8.0_66\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Users\chennan\bin;E:\dev\Git\mingw64\bin;E:\dev\Git\usr\local\bin;E:\dev\Git\usr\bin;E:\dev\Git\usr\bin;E:\dev\Git\mingw64\bin;E:\dev\Git\usr\bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;E:\dev\Java\jdk1.8.0_66\bin;E:\dev\apache-maven-3.3.9\bin;E:\dev\Git\cmd;E:\dev\Git\usr\bin;E:\dev\TortoiseGit\bin;E:\dev\mysql\MySQL\MySQL Server 5.5\bin;E:\dev\apache-jmeter-2.13\apache-jmeter-2.13\bin;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;D:\software\ssh\SSHSecureShellClient-3.2.9;E:\dev\apache-groovy-sdk-2.4.7\groovy-2.4.7\bin;E:\dev\Git\usr\bin\vendor_perl;E:\dev\Git\usr\bin\core_perl;."/>
<property name="java.specification.name" value="Java Platform API Specification"/>
<property name="java.class.version" value="52.0"/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="os.version" value="6.1"/>
<property name="user.home" value="C:\Users\chennan"/>
<property name="user.timezone" value="Asia/Shanghai"/>
<property name="java.awt.printerjob" value="sun.awt.windows.WPrinterJob"/>
<property name="java.specification.version" value="1.8"/>
<property name="file.encoding" value="GBK"/>
<property name="user.name" value="chennan"/>
<property name="java.class.path" value="E:/dev/apache-maven-3.3.9/boot/plexus-classworlds-2.5.2.jar"/>
<property name="java.vm.specification.version" value="1.8"/>
<property name="sun.arch.data.model" value="64"/>
<property name="java.home" value="E:\dev\Java\jdk1.8.0_66\jre"/>
<property name="sun.java.command" value="org.codehaus.plexus.classworlds.launcher.Launcher clean test"/>
<property name="java.specification.vendor" value="Oracle Corporation"/>
<property name="user.language" value="zh"/>
<property name="awt.toolkit" value="sun.awt.windows.WToolkit"/>
<property name="java.vm.info" value="mixed mode"/>
<property name="java.version" value="1.8.0_66"/>
<property name="java.ext.dirs" value="E:\dev\Java\jdk1.8.0_66\jre\lib\ext;C:\Windows\Sun\Java\lib\ext"/>
<property name="sun.boot.class.path" value="E:\dev\Java\jdk1.8.0_66\jre\lib\resources.jar;E:\dev\Java\jdk1.8.0_66\jre\lib\rt.jar;E:\dev\Java\jdk1.8.0_66\jre\lib\sunrsasign.jar;E:\dev\Java\jdk1.8.0_66\jre\lib\jsse.jar;E:\dev\Java\jdk1.8.0_66\jre\lib\jce.jar;E:\dev\Java\jdk1.8.0_66\jre\lib\charsets.jar;E:\dev\Java\jdk1.8.0_66\jre\lib\jfr.jar;E:\dev\Java\jdk1.8.0_66\jre\classes"/>
<property name="java.vendor" value="Oracle Corporation"/>
<property name="maven.home" value="E:\dev\apache-maven-3.3.9"/>
<property name="file.separator" value="\"/>
<property name="java.vendor.url.bug" value="http://bugreport.sun.com/bugreport/"/>
<property name="sun.cpu.endian" value="little"/>
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
<property name="sun.desktop" value="windows"/>
<property name="sun.cpu.isalist" value="amd64"/>
</properties>
<testcase classname="org.elasticsearch.query.SqlParserLimitTest" name="testParseLimitExprWithArgs" time="1.24"/>
<testcase classname="org.elasticsearch.query.SqlParserLimitTest" name="testX" time="0.026"/>
<testcase classname="org.elasticsearch.query.SqlParserLimitTest" name="testParseLimitExpr" time="0.013"/>
</testsuite>
Loading

0 comments on commit 8d7443d

Please sign in to comment.