我在ElasticSearch 5.5中有以下doc(s)索引。现在我想搜索包含id = P123的人的所有文档。我该如何编写JSON搜索查询?
{
"my_id": "ABC123",
"legacy_id": "",
"alias": "",
"persons": [
{
"id": "P123",
"roles": [
{
"role": "",
"status": "",
"status_start_datetime": ""
}
]
},
{
"id": "P124",
"roles": [
{
"role": "",
"status": "",
"status_start_datetime": ""
}
]
},
]
}
答案 0 :(得分:0)
以下查询应该找到您的期望:
public class AbstractCsvParser {
public <T> List<T> readCsvFile(String fileName, String[] headers, Function<CSVRecord, T> mapper) {
FileReader fileReader = null;
CSVParser csvFileParser = null;
CSVFormat csvFileFormat = CSVFormat.DEFAULT.withHeader(headers);
List<T> entities = new ArrayList<>();
try {
fileReader = new FileReader(fileName);
csvFileParser = new CSVParser(fileReader, csvFileFormat);
//Get a list of CSV file records
List csvRecords = csvFileParser.getRecords();
//Read the CSV file. Header is ignored (i == 1)
for (int i = 1; i < csvRecords.size(); i++) {
CSVRecord record = (CSVRecord) csvRecords.get(i);
T result = mapper.apply(record); // transform to desired enitity
entities.add(result);
}
} catch (Exception e) {
// omitted
}
return entities;
}
}