ElasticSearch 5.5:搜索内部字段值

时间:2018-02-02 20:28:26

标签: elasticsearch

我在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": ""
            }
          ]
        },     
      ]
    }

1 个答案:

答案 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;
    }
}