如何使用Url初始化OutputStream?(How to initialise an OutputStream with a Url?)
我尝试创建一个OutputStream到一个app组文件夹,创建如下:
func createProjectDirectoryPath(path:String) -> String { let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.xyz") let logsPath = containerURL!.appendingPathComponent(path) NSLog("12345- folder path: %@", logsPath.path) do { try FileManager.default.createDirectory(atPath: logsPath.path, withIntermediateDirectories: true, attributes: nil) } catch let error as NSError { NSLog("12345- Unable to create directory %@", error.debugDescription) } return logsPath.path }
这个函数给了我这样的路径
/private/var/mobile/Containers/Shared/AppGroup/40215F20-4713-4E23-87EF-1E21CCFB45DF/pcapFiles
此文件夹存在,因为行FileManager.default.fileExists(path)返回true。 下一步是将生成的文件名附加到路径,我在这里做
let urlToFile = URL(string: createProjectDirectoryPath(path: "pcapFiles").appending("/\(filename)"))
这给了我正确的新路径
/private/var/mobile/Containers/Shared/AppGroup/40215F20-4713-4E23-87EF-1E21CCFB45DF/pcapFiles/39CC2DB4-A6D9-412E-BAAF-2FAA4AD70B22.pcap
如果我称这行,
ostream
总是为零let ostream = OutputStream(url: urlToFile!, append: false)
我错过了什么吗? OutputStream应该在此路径上创建文件,但由于未知原因,它是不可能的。
PS:AppGroup在功能和开发人员控制台中启用。
I try to create an OutputStream to an app group folder, which is created as follows:
func createProjectDirectoryPath(path:String) -> String { let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.xyz") let logsPath = containerURL!.appendingPathComponent(path) NSLog("12345- folder path: %@", logsPath.path) do { try FileManager.default.createDirectory(atPath: logsPath.path, withIntermediateDirectories: true, attributes: nil) } catch let error as NSError { NSLog("12345- Unable to create directory %@", error.debugDescription) } return logsPath.path }
This function gives me a path like this
/private/var/mobile/Containers/Shared/AppGroup/40215F20-4713-4E23-87EF-1E21CCFB45DF/pcapFiles
This folder exists, because the line FileManager.default.fileExists(path) returns true. The next step is to append a generated filename to the path, which I am doing here
let urlToFile = URL(string: createProjectDirectoryPath(path: "pcapFiles").appending("/\(filename)"))
which gives me the correct new path
/private/var/mobile/Containers/Shared/AppGroup/40215F20-4713-4E23-87EF-1E21CCFB45DF/pcapFiles/39CC2DB4-A6D9-412E-BAAF-2FAA4AD70B22.pcap
If I call this line,
ostream
is always nillet ostream = OutputStream(url: urlToFile!, append: false)
Do I miss something? The OutputStream should create the file on this path, but for unknown reason, it is not possible.
PS: AppGroup is enabled in Capabilities and in developers console.
原文:https://stackoverflow.com/questions/44366129
最满意答案
您需要先关闭索引,更新分析器设置,然后打开索引。 这是更新现有分析仪设置的唯一方法。 请注意,更改在索引但未使用时未使用的分析器是有意义的
curl -XPOST 'localhost:9200/schoolrecords/_close' curl -XPUT 'localhost:9200/schoolrecords/_settings' -d '{ "analysis" : { "analyzer" : { "synonym" : { "tokenizer" : "whitespace", "filter" : ["synonym"] } }, "filter" : { "synonym" : { "type" : "synonym", "synonyms_path" : "synonym.txt", "ignore_case" : true } } } }' curl -XPOST 'localhost:9200/schoolrecords/_open'
You need to first close the index , update analyzer settings and then open the index. That is the only way to update existing analyzer settings. Note that it only makes sense to change analyzers which are not used while indexing but used
curl -XPOST 'localhost:9200/schoolrecords/_close' curl -XPUT 'localhost:9200/schoolrecords/_settings' -d '{ "analysis" : { "analyzer" : { "synonym" : { "tokenizer" : "whitespace", "filter" : ["synonym"] } }, "filter" : { "synonym" : { "type" : "synonym", "synonyms_path" : "synonym.txt", "ignore_case" : true } } } }' curl -XPOST 'localhost:9200/schoolrecords/_open'
相关问答
更多-
elasticsearch多词关键词 - 标记化同义词分析(elasticsearch multi-word keyword-tokenized synonym analysis)[2019-11-03]
“tokenizer”:“keyword”键值也需要添加到my_syn_filt过滤器声明中,如下所示: curl -XPOST "http://localhost:9200/test" -d' { "settings": { "index": { "analysis": { "filter": { "my_syn_filt": { "tokenizer": "keyword", "type": "s ... -
在你的查询中添加“_source”:“false”。 喜欢这个: {"_source": "false", "query": ... } 这将只搜索命中并且不会访问存储的字段以供检索。 In your query add "_source": "false". Like this: {"_source": "false", "query": ... } This will only search for hits and won't access the stored fields for retr ...
-
Elasticsearch:更新索引分析器后,索引需要一个reindex吗?(Elasticsearch: After update index analyzer, index need a reindex?)[2022-11-17]
答案是肯定的。 您需要以相同的方式索引所有数据。 这可能是获得“奇怪”结果的原因。 已经索引的数据根据先前定义的分析器的规则进行索引。 更改分析器后索引的任何数据都会被新规则索引。 由于您的查询现在也会被新规则分析,因此可能无法从旧的索引数据集中生成结果。 您现在可以通过弹性reindex api轻松重新索引数据。 阅读: https : //www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html如果您担心停机时间, ... -
同义词分析器不工作(Synonym analyzer not working)[2024-03-08]
你很接近,但我建议从文档中仔细阅读本节以更好地理解这个功能。 作为解决方案: PUT /countries { "mappings": { "country": { "properties": { "countryName": { "type": "string", "analyzer": "synonym" } } } }, "settings": { "analysis": ... -
默认分析器设置会影响真实的索引文档,而不会影响您使用http:// localhost:9200 / _analyze执行的“测试”请求。 尝试将少量文档添加到索引中,然后查看搜索是否按预期工作 Default analyzer settings affects real indexed documents, not "test" requests you do with http://localhost:9200/_analyze. Try to add few docs to an index and ...
-
Elasticsearch Python - 索引分析器和搜索分析器(Elasticsearch Python - Index Analyzer & Search Analyzer)[2021-11-25]
client.indices.create( index=index, body={ 'settings': { # just one shard, no replicas for testing 'number_of_shards': 1, 'number_of_replicas': 0, # custom analyzer for analyzing file paths 'analysis': ... -
我找到的最接近的解决方案如下。 @Document(indexName = "myindex", type = "mytype") @Setting(settingPath = "/mysetting/mysetting.json") public class Employee implements Serializable { @Id private String employeeId; @Field(type = FieldType.String, analyzer = "s ...
-
这是因为您使用了不分析输入的term查询。 你应该改变它来使用一个match查询,而且一切都会好的 GET people/person/_search { "query": { "bool": { "should": [ { "match": { "state": "al" } } ] } } } This is because you've used a ter ...
-
您需要先关闭索引,更新分析器设置,然后打开索引。 这是更新现有分析仪设置的唯一方法。 请注意,更改在索引但未使用时未使用的分析器是有意义的 curl -XPOST 'localhost:9200/schoolrecords/_close' curl -XPUT 'localhost:9200/schoolrecords/_settings' -d '{ "analysis" : { "analyzer" : { "synonym" : { "tokenizer ...
-
Elasticsearch查询字符串查询不能与同义词分析器一起使用(Elasticsearch Query String Query not working with synonym analyzer)[2022-05-12]
嗯,我不认为Elasticsearch会知道“翻译” fil到vid :-)。 因此,我认为在索引和搜索时都需要edgeNGram 。 PUT test { "settings": { "analysis": { "analyzer": { "category_synonym": { "tokenizer": "whitespace", "filter": [ "synonym_filter", ...