创建索引嵌套 [英] Creating an index Nest
问题描述
如何使用 Elasticsearch Nest API 重新创建以下索引?
How would I recreate the following index using Elasticsearch Nest API?
这里是包含映射的索引的 json:
Here is the json for the index including the mapping:
{
"settings": {
"analysis": {
"filter": {
"trigrams_filter": {
"type": "ngram",
"min_gram": 3,
"max_gram": 3
}
},
"analyzer": {
"trigrams": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"trigrams_filter"
]
}
}
}
},
"mappings": {
"data": {
"_all" : {"enabled" : true},
"properties": {
"text": {
"type": "string",
"analyzer": "trigrams"
}
}
}
}
}
这是我的尝试:
var newIndex = client.CreateIndexAsync(indexName, index => index
.NumberOfReplicas(replicas)
.NumberOfShards(shards)
.Settings(settings => settings
.Add("merge.policy.merge_factor", "10")
.Add("search.slowlog.threshold.fetch.warn", "1s")
.Add("mapping.allow_type_wrapper", true))
.AddMapping<Object>(mapping => mapping
.IndexAnalyzer("trigram")
.Type("string"))
);
文档中没有提及任何相关内容?
The documentation does not mention anything about this?
更新:
找到这个 使用的帖子var index = new IndexSettings()
然后使用字符串文字 json 添加 Analysis.
and then adds Analysis with the string literal json.
index.Add("analysis", @"{json});
在哪里可以找到更多这样的例子并且这是否有效?
Where can one find more examples like this one and does this work?
推荐答案
在旧版本中创建索引
如嵌套创建索引文档:
这里是直接将索引设置声明为 Fluent Dictionary 条目的方式.就像您在上面的示例中所做的一样.我在本地进行了测试,它生成了与上面的 JSON 匹配的索引设置.
Here is the way where you directly declare the index settings as Fluent Dictionary entries. Just like you are doing in your example above. I tested this locally and it produces the index settings that match your JSON above.
var response = client.CreateIndex(indexName, s => s
.NumberOfReplicas(replicas)
.NumberOfShards(shards)
.Settings(settings => settings
.Add("merge.policy.merge_factor", "10")
.Add("search.slowlog.threshold.fetch.warn", "1s")
.Add("mapping.allow_type_wrapper", true)
.Add("analysis.filter.trigrams_filter.type", "nGram")
.Add("analysis.filter.trigrams_filter.min_gram", "3")
.Add("analysis.filter.trigrams_filter.max_gram", "3")
.Add("analysis.analyzer.trigrams.type", "custom")
.Add("analysis.analyzer.trigrams.tokenizer", "standard")
.Add("analysis.analyzer.trigrams.filter.0", "lowercase")
.Add("analysis.analyzer.trigrams.filter.1", "trigrams_filter")
)
.AddMapping<Object>(mapping => mapping
.Type("data")
.AllField(af => af.Enabled())
.Properties(prop => prop
.String(sprop => sprop
.Name("text")
.IndexAnalyzer("trigrams")
)
)
)
);
请注意,NEST 还包括使用强类型类创建索引设置的能力.稍后我会发布一个示例,如果我有时间来完成它.
Please note that NEST also includes the ability to create index settings using strongly typed classes as well. I will post an example of that later, if I have time to work through it.
另请注意,在 NEST 7.x 中删除了 CreateIndex
方法.使用 Indices.Create
代替.这是示例.
Please also note that in NEST 7.x CreateIndex
method is removed. Use Indices.Create
isntead. Here's the example.
_client.Indices
.Create(indexName, s => s
.Settings(se => se
.NumberOfReplicas(replicas)
.NumberOfShards(shards)
.Setting("merge.policy.merge_factor", "10")));
这篇关于创建索引嵌套的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!