ElasticSearch / NEST:确定Mapping是否已存在(ElasticSearch/NEST: Determine if Mapping already exists)
我正在使用NEST客户端来访问我的ElasticSearch索引/映射。 我正在尝试确定映射是否已存在,如果没有创建新映射。
IndexExistsAsync()
有一种方法,但似乎没有MappingExistsAsync()
方法。GetMappingAsync()
返回一个IGetMappingResponse
,它有一个布尔的IsValid
,我认为我可以检查,但是如果映射不存在,调用GetMappingAsync()
只会引发异常。 我可以检查是否抛出异常并创建映射,但是有更好的方法来处理它吗?I'm using the NEST client to access my ElasticSearch indexes/mappings. I'm trying to determine if a mapping already exists, and if not create a new mapping. There's a method for
IndexExistsAsync()
but there doesn't appear to be aMappingExistsAsync()
method.GetMappingAsync()
returns anIGetMappingResponse
which has a booleanIsValid
, that I thought I might be able to check, but callingGetMappingAsync()
just throws an exception if the mapping doesn't exist. I can just check if an exception is thrown and create the mapping, but is there a better way of handling this?
原文:https://stackoverflow.com/questions/35852130
最满意答案
如果行中没有选项卡,则会出现异常。
你应该在访问第二个元素之前检查是否tokens.length()> 1。
if no tab exists in the line you get the exception.
you should check if tokens.length()>1 before accessing the second element.
相关问答
更多-
如何使用Java中的文件中的特定行号来读取特定的行?(How to read a specific line using the specific line number from a file in Java?)[2022-12-01]
除非您以前有关于文件中的行的知识,否则无法直接访问第32行,而不读取31行以前的行。 所有语言和所有现代文件系统都是如此。 所以有效地你只需读取行,直到找到第32个。 Unless you have previous knowledge about the lines in the file, there's no way to directly access the 32nd line without reading the 31 previous lines. That's true for all l ... -
如果行中没有选项卡,则会出现异常。 你应该在访问第二个元素之前检查是否tokens.length()> 1。 if no tab exists in the line you get the exception. you should check if tokens.length()>1 before accessing the second element.
-
这一行: studentList = new Student[10]; 创建一个包含10个元素的数组。 每个元素的值不是Student 对象 ; 它是一个引用 - 该引用将为null,或者对Student对象(或兼容类型)的引用。 每个元素都有一个空值开头。 该行不会创建任何Student对象 。 您需要在设置其属性之前创建Student实例,例如 if (scanner.hasNext()) { studentList[counter] = new Student(); studentList[ ...
-
如果您想操纵任何类型的文件,请不要认为它们包含文本数据,并将它们视为包含字节的二进制文件。 使用输入和输出流读取和写入二进制文件。 下面是一个读取文件并将其拆分为写入N个输出文件的1024字节的方法的示例: import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class FileSplit { public s ...
-
尝试逐行读取文件时出现NullPointerException(Java)?(NullPointerException when trying to read a file line by line (Java)?)[2020-11-30]
当你开始你的for循环时,阅读器已经在文件的末尾(来自while循环)。 因此, readLine()将始终返回null 。 在第一次读取文件时,您应该摆脱for循环并在while循环中执行所有工作。 By the time you start your for loop, the reader is already at the end of the file (from the while loop). Therefore, readLine() will always return null. You ... -
我努力了 ... String[] cols = line.split("|"); ... 这不起作用,因为split采用正则表达式,并且| 解释为正则表达式时是一个特殊字符 。 相反,试试吧 String[] cols = line.split("\\|"); ^^ I have tried ... String[] cols = line.split("|"); ... This doesn't work since sp ...
-
请参阅http://wiki.netbeans.org/DevFaqOpenFileAtLine LineCookie - 请参阅https://forums.netbeans.org/topic59253.html 要么 NbDocument#openDocument() - 参见http://bits.netbeans.org/dev/javadoc/org-openide-text/org/openide/text/NbDocument.html#openDocument(org.openide.ut ...
-
您有可能将输入文件转换为CSV吗? 将更容易阅读和解析... https://www.mkyong.com/java/how-to-read-and-parse-csv-file-in-java/ 然后你可以简单地读取一行并获得该车辆/汽车/卡车的所有数据/你需要传递给构造函数的任何数据。 编辑如果没有,我会做一些接近以下的事情。 注意 - 这是在C#中,但在Java中也可以这样做。 using System; using System.Collections.Generic; using System.L ...
-
这很容易。 您只需从每一行读取5个变量,并忽略您没有进一步使用的变量。 就像是 do i = 1, 100 read(*,*) a(i), b, c(i), d, e end do 这将在每次迭代时覆盖b , d和e中的值。 顺便说一下,你的路线 99 continue 是多余的; 它不是用作do循环的结束行,而是你没有从其他地方分支到它。 如果您从看不见的代码分支到它,您可以将标签99附加到下一行并删除continue语句。 一般来说,现代Fortran中的continue是多余的; 特别是你 ...
-
Stream是使用循环的替代方法。 您不能多次使用Stream。 即使你可以多次使用一个流来调用toArray() ,每行输入两次也会非常昂贵。 你能做的是 try (Stream
stream = Files.lines(file.toPath())) { stream.forEach(System.out::println); } 注意:使用此方法的一个显着优点是它可以在读取文件时打印文件。 这意味着无论文件有多大,它仍然可以读取它。 如果您对每一行使用集合或数组,则您读取的文 ...