小编vma*_*san的帖子

如何以可靠的方式编写/更新Oracle blob?

我正在尝试在blob列中编写和更新pdf文档,但我只能更新blob,只写入比以前存储的数据更多的数据.如果我尝试用较小的文档数据更新blob列,我只会得到一个损坏的pdf.

首先使用empty_blob()函数初始化blob列.我在下面编写了示例Java类来测试此行为.我第一次以'true'作为main方法的第一个参数运行它,所以在第一行中存储了大约31kB的文档,在第二行中存储了一个278kB的文档.然后我用'false'作为参数运行它,这样两行应该更新交换文件.结果是,只有当我写入比现有数据更多的数据时才能得到正确的结果.

如何编写一种以可靠的方式编写和更新blob的方法而不必担心二进制数据的大小?

import static org.apache.commons.io.IOUtils.copy;

import java.io.FileInputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import oracle.jdbc.OracleDriver;
import oracle.jdbc.OracleResultSet;
import oracle.sql.BLOB;

import org.apache.commons.lang.ArrayUtils;
/**
 * Prerequisites:
 * 1) a table named 'x' must exists [create table x (i number, j blob);] 
 * 2) that table should have two columns [insert into x (i, j) values (1, empty_blob()); insert into x (i, j) values (2, empty_blob()); commit;]
 * 3) download lsp.pdf from http://www.objectmentor.com/resources/articles/lsp.pdf
 * …
Run Code Online (Sandbox Code Playgroud)

java oracle blob jdbc

25
推荐指数
2
解决办法
7万
查看次数

Spring Boot Elasticsearch配置

我有一个工作的Spring Boot Elasticsearch Application,它使用两个配置文件之一:application.dev.properties或application.prod.properties.那部分工作正常.我遇到了从application.xxx.properties读取外部elasticsearch的问题.

这有效:

@Configuration
@PropertySource(value = "classpath:config/elasticsearch.properties")
public class ElasticsearchConfiguration {

    @Resource
    private Environment environment;

    @Bean
    public Client client() {
        TransportClient client = new TransportClient();
        TransportAddress address = new InetSocketTransportAddress(
                environment.getProperty("elasticsearch.host"), 
                Integer.parseInt(environment.getProperty("elasticsearch.port"))
        );
        client.addTransportAddress(address);        
        return client;
    }

    @Bean
    public ElasticsearchOperations elasticsearchTemplate() {
        return new ElasticsearchTemplate(client());
    }
}
Run Code Online (Sandbox Code Playgroud)

但显然无法解决我的多环境问题.

我还尝试了@Value注释主机和端口变量没有成功.

如何转换上面的内容以从应用程序属性文件中读取其值,或者根据我想要运行的任何配置文件选择不同的@PropertySource文件?

spring.data.elasticsearch.properties.host = 10.10.1.10
spring.data.elasticsearch.properties.port = 9300
Run Code Online (Sandbox Code Playgroud)

谢谢

java elasticsearch spring-boot

12
推荐指数
1
解决办法
3万
查看次数

在ElasticSearch上等效的Solr的copyField?

有人能告诉我ElasticSearch上是否有相同的Solr copyField指令?

我知道有多字段类型: http ://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html当你想在同一个字段上应用多个分析器时,这很好.

但它并不完全相同.Solr允许将多个字段"合并"为一个:

<field name="id" type="string" indexed="true" stored="true"/>
<field name="name" type="string" indexed="true" stored="true"/>
<field name="subject" type="string" indexed="true" stored="true"/>
<field name="location" type="string" indexed="true" stored="true"/>
<field name="all" type="text" indexed="true" stored="true" multiValued="true"/>
<copyField source="*" dest="all"/>
Run Code Online (Sandbox Code Playgroud)

这个插件很有前途:https: //github.com/yakaz/elasticsearch-analysis-combo

因为它允许在使用ElasticSearch多值字段时将结果作为单个字段返回.但它仍然不完全相同,因为它不允许"合并"多个字段.


我想要Combo分析器和Solr copyField的组合.

我有一个博客文章模型(标题/描述字段),并希望在单个字段"blogContent"上复制标题和描述,我将在其中应用2个不同的分析器.

ElasticSearch有解决方案吗?

lucene search solr elasticsearch elasticsearch-5

11
推荐指数
2
解决办法
3952
查看次数

WebFlux功能:如何检测空Flux并返回404?

我有以下简化的处理函数(Spring WebFlux和使用Kotlin的函数API).但是,当Flux为空时,我需要提示如何检测空Flux然后对404使用noContent().

fun findByLastname(request: ServerRequest): Mono<ServerResponse> {
    val lastnameOpt = request.queryParam("lastname")
    val customerFlux = if (lastnameOpt.isPresent) {
        service.findByLastname(lastnameOpt.get())
    } else {
        service.findAll()
    }
    // How can I detect an empty Flux and then invoke noContent() ?
    return ok().body(customerFlux, Customer::class.java)
}
Run Code Online (Sandbox Code Playgroud)

spring kotlin spring-boot project-reactor spring-webflux

7
推荐指数
4
解决办法
9576
查看次数

elasticsearch-dsl 使用 from 和 size

我使用 python 2.7 和 Elasticsearch-DSL 包来查询我的弹性集群。

尝试向查询添加“来自和限制”功能,以便在我的 FE 中进行分页,该 FE 呈现文档弹性返回,但“来自”无法正常工作(即我没有正确使用它,我的配偶)。

相关代码是:

s = Search(using=elastic_conn, index='my_index'). \
       filter("terms", organization_id=org_list)

    hits = s[my_from:my_size].execute() # if from = 10, size = 10 then I get 0 documents, altought 100 documents match the filters.
Run Code Online (Sandbox Code Playgroud)

我的索引包含 100 个文档。即使我的过滤器匹配所有结果(即没有过滤掉任何内容), 例如,如果我使用my_from = 10and ,那么我在命中中什么也得不到(没有匹配的文档)my_size = 10

这是为什么?我是否滥用了 from ?

文件指出:

来自和尺寸参数。from 参数定义距您要获取的第一个结果的偏移量。size 参数允许您配置要返回的最大命中数。

所以这看起来很简单,我错过了什么?

python-2.7 elasticsearch

6
推荐指数
2
解决办法
1万
查看次数