当使用spring-data插入带有Date类型的Elasticsearch文档时,我无法获得正确的日期格式,日期格式始终为Long.
这是java代码:Entity.java
import java.util.Date;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
import com.fasterxml.jackson.annotation.JsonProperty;
@Document(indexName = "entity-index", type = "entity-type")
public class Entity {
@Id
private String id;
@Field(type = FieldType.Date, index = FieldIndex.not_analyzed, store = true,
format = DateFormat.custom, pattern = "yyyy-MM-dd'T'hh:mm:ss.SSS'Z'")
private Date createDate;
private String system;
private double score;
@Field(type = FieldType.Date, format = DateFormat.date_optional_time)
@JsonProperty(value = "@timestamp")
private Date updateDate;
// omit setter and getter
}
Run Code Online (Sandbox Code Playgroud)
这是测试
public class EntityDAOTest {
@Autowired …Run Code Online (Sandbox Code Playgroud) 我使用spring-data-elasticsearch框架从elasticsearch服务器获取查询结果,java代码如下:
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(matchAllQuery()).withSearchType(SearchType.COUNT)
.addAggregation(new MinBuilder("min_createDate").field("createDate"))
.build();
List<Entity> list = template.queryForList(searchQuery, Entity.class);
Run Code Online (Sandbox Code Playgroud)
虽然我怎么知道发送到elasticssearch服务器的原始http查询?如何启用日志记录,我尝试添加log4j,但似乎spring-data-elasticsearch不记录查询.
在javascript中,我可以编写以下代码:
response = {
status: 1,
data: {
key : 2
}
}
var result = `status is ${response.status}, data key is ${response.data.key}`
console.log(result);
Run Code Online (Sandbox Code Playgroud)
输出是
status is 1, data key is 2
Run Code Online (Sandbox Code Playgroud)
有没有任何库提供在Java中执行以下功能的方法?
String xxxFunction(Map map, String template)
Run Code Online (Sandbox Code Playgroud)
请注意${response.data.key}地图中地图的用法
这是我的elasticsearch服务器中的数据:
{"system": "aaa"},
{"system": "bbb"},
{"system": null}
Run Code Online (Sandbox Code Playgroud)
我想得到系统的统计数据.然后我做了查询:
{
"aggs" : {
"myAggrs" : {
"terms" : { "field" : "system" }
}
}
Run Code Online (Sandbox Code Playgroud)
它给了我结果:
{
"key": "aaa",
"doc_count": 1
},
{
"key": "bbb",
"doc_count": 1
}
Run Code Online (Sandbox Code Playgroud)
但是"key" : null结果中没有包含,我怎么能得到它?这是我期望的结果:
{
"key": "aaa",
"doc_count": 1
},
{
"key": "bbb",
"doc_count": 1
},
{
"key": null,
"doc_count": 1
}
Run Code Online (Sandbox Code Playgroud) 我使用 webpack 来构建 React 组件。这是 JSX 文件:
// index.js
var React = require('react');
var ReactDOM = require('react-dom');
var renderHelloComponnet = function(id) {
ReactDOM.render(
<h1>Hello, World!</h1>,
document.getElementById(id)
);
}
Run Code Online (Sandbox Code Playgroud)
然后,我想renderHelloComponnet在 html 中调用该函数,我有 webpack 的配置文件:
module.exports = {
entry: {
index: './src/index.js'
},
output: {
path: __dirname + '/build',
filename: '[name].bundle.js',
libraryTarget: "var",
library: ["ABC"],
},
resolve: {
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: { presets:['react'] }
}
] …Run Code Online (Sandbox Code Playgroud) 如果我有一个文件test.txt:
example 1 content 2013-3-8:
hello java
example 2 content 2013-4-9:
hello c
Run Code Online (Sandbox Code Playgroud)
如何使用awk或sed将test.txt分隔为两个文件
TEST1
hello java
Run Code Online (Sandbox Code Playgroud)
TEST2
hello c
Run Code Online (Sandbox Code Playgroud)
我使用以下命令:
awk '/example/{i++}{print > "test"i}' test.txt
Run Code Online (Sandbox Code Playgroud)
但它仍将是第一线(例如XXX),我可以将某些片段添加到打印在awk来删除第一线?
我想通过分隔符"|"拆分String 在Java中获取String数组,这是我的代码:
String str = "123|sdf||";
String[] array = str.split("\\|");
Run Code Online (Sandbox Code Playgroud)
我将得到2个元素的数组:"123","sdf".我期望阵列有4个元素:"123","sdf","",""; 我可以用任何现有的课程吗?我也试过StringTokernizer,不起作用
我需要将数据从oracle中的表转储到elasticsearch(1亿条记录),我的JVM内存限制是256M,我使用下面的代码和配置从oracle(mybatis + spring)获取数据:接口:
package com.fudy.mapper;
import java.util.List;
import com.fudy.domain.Person;
public interface PersonMapper {
List<Person> selectAllPerson();
}
Run Code Online (Sandbox Code Playgroud)
xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fudy.mapper.PersonMapper">
<resultMap type="com.fudy.domain.Person" id="PersonAlias">
<id column="ID" property="id" />
<result column="NAME" property="name" />
</resultMap>
<select id="selectAllPerson" fetchSize="10000" resultMap="PersonAlias">
SELECT * FROM person
</select>
</mapper>
Run Code Online (Sandbox Code Playgroud)
ApplicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
<tx:annotation-driven transaction-manager="transactionManager" />
<context:property-placeholder location="classpath:db.properties"/>
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">
<property …Run Code Online (Sandbox Code Playgroud) 在向statsd发送数据时:
echo "foo:1|c" | nc -u -w0 127.0.0.1 8125
Run Code Online (Sandbox Code Playgroud)
statsd将在刷新后输出结果并将数据插入到InfluxDB中:
{ counters:
{ 'statsd.bad_lines_seen': 0,
'statsd.packets_received': 1,
'statsd.metrics_received': 1,
foo: 1 },
timers: {},
gauges: { 'statsd.timestamp_lag': 0 },
timer_data: {},
counter_rates:
{ 'statsd.bad_lines_seen': 0,
'statsd.packets_received': 0.03333333333333333,
'statsd.metrics_received': 0.03333333333333333,
foo: 0.03333333333333333 },
sets: {},
pctThreshold: [ 90 ] }
Run Code Online (Sandbox Code Playgroud)
运行命令以显示InfluxDB信息:
$curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=mydb" --data-urlencode "q=SHOW MEASUREMENTS"
Run Code Online (Sandbox Code Playgroud)
会成功回复:
{
"results": [
{
"series": [
{
"name": "measurements",
"columns": [
"name"
],
"values": [
[
"cpu_load_short"
],
[
"foo.counter"
] …Run Code Online (Sandbox Code Playgroud) 这是反应的入门示例,在示例中,波纹管代码片段位于单独的main.js文件中:
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('example')
);
Run Code Online (Sandbox Code Playgroud)
如果页面不包含id:'example',例如home.html(只有id:example1),index.html(只有id:example2),那么如何<h1>Hello, world!</h1>在这些页面中重用?