我有一个关于elasticsearch索引模板的问题,我的问题有一个场景。
为一系列索引创建一个模板,命名为templateA,并且有一些从这个模板创建的索引,命名为Index-yyyy.mm.dd2和Index-yyyy.mm.dd2。一段时间后,我需要在索引中创建一些新字段,并更新templateA.
SO,如何使之前创建的索引使用新模板?请给我一些建议。非常感谢!
我有这个文件
{
"text_foo": "lorem ipsum",
"one":{
"two":{
"three":{
"text_bar": "dolor sit amet"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想要完成的事情:我需要动态模板,它将匹配以“text_”开头的任何属性示例:
"mappings" : {
"dynamic_templates":[
{
"text":{
"match": "text_*",
"path_match": "*.text_*",
"match_mapping_type": "*",
"mapping":{"type":"text","analyzer":"myCustomAnalyzer"}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
"match"和可以"path_match"一起使用吗?(就像我的例子一样)
会"path_match":"*.text_*"匹配整个路径"one.two.three.text_*"还是仅匹配“one.text_*”?
也会"path_match":"*.text_*"匹配 root 属性吗"text_foo"?
如果唯一的解决方案是使用正则表达式 ( "match_pattern":"regex"),则正则表达式将匹配整个路径"one.two.three.text_bar"还是仅匹配"text_bar"?
mapping elasticsearch elasticsearch-mapping elasticsearch-template
我一直在努力使用 Elasticsearch 模板,特别是在可选参数方面。我想在那里添加可选的过滤器。这是我正在尝试的代码片段:
{
"filter" : {
"bool" : {
"must" : [
{{#ProductIDs.0}}
{ "terms" : { "Product.ProductID" : [{{#ProductIDs}}{{.}},{{/ProductIDs}}] } }
{{/ProductIDs.0}}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
当然,我"用替换\",丑化它,将它包裹在 中{ "template" :"_snippet_above_" }。
现在,当我尝试使用以下命令调用它时:
GET /statistic/_search/template
{
"template": {
"id": "test"
},
"params": {
"ProductIDs": [1,2]
}
}
Run Code Online (Sandbox Code Playgroud)
它忽略我提供的参数,但是当我尝试在官方 Mustache.io 演示页面中执行此操作时 - 它工作得很好。
我{{#ProductIDs.length}}也尝试过选项 - 但没有成功。经过一些研究后,我发现Mustache.js和Mustache.java之间有一个区别。我假设Elasticsearch使用JAVA版本,它不支持长度参数,所以我必须依赖isEmpty。所以我重写了我的查询如下:
{
"filter" : {
"bool" : {
"must" : [ …Run Code Online (Sandbox Code Playgroud) java templates mustache elasticsearch elasticsearch-template
我是 ElasticsearchTemplate 的新手。我想根据我的查询从 Elasticsearch 获取 1000 个文档。我已经使用 QueryBuilder 创建了我的查询,它运行良好。我浏览了以下链接,其中指出可以使用扫描和滚动来实现大数据集。
链接一
链接二
我正在尝试在以下代码部分中实现此功能,我从上面提到的链接之一复制粘贴了这些代码。但我收到以下错误:
The type ResultsMapper is not generic; it cannot be parameterized with arguments <myInputDto>.
MyInputDto是@Document我项目中带有注释的类。一天结束,我只想从 Elasticsearch 检索 1000 个文档。我试图找到size参数,但我认为它不受支持。
String scrollId = esTemplate.scan(searchQuery, 1000, false);
List<MyInputDto> sampleEntities = new ArrayList<MyInputDto>();
boolean hasRecords = true;
while (hasRecords) {
Page<MyInputDto> page = esTemplate.scroll(scrollId, 5000L,
new ResultsMapper<MyInputDto>() {
@Override
public Page<MyInputDto> mapResults(SearchResponse response) {
List<MyInputDto> chunk = new ArrayList<MyInputDto>();
for (SearchHit searchHit : response.getHits()) {
if (response.getHits().getHits().length …Run Code Online (Sandbox Code Playgroud)