Query data parsing

The source query

  • The source filter

    String[] includeFields = new String[] {"test1", "test2"}; String[] excludeFields = new String[] {"test1", "test2"}; sourceBuilder.fetchSource(includeFields, excludeFields);Copy the code
  • Source does not need to be filtered, and all fields are returned without configuration

  • Source close

    sourceBuilder.fetchSource(false)
    Copy the code

Source Obtain data

String sourceStr = oneHit.getSourceAsString();
JSONObject json = new JSONObject(sourceStr);

Map<String Object> map = oneHit.getSourceAsMap();
Copy the code

Doc the value to query

  • Add fields to return, including field name + formatting
    • Use_field_mapping: use format from the mapping
    • epoch_millis:
    • The date type supports a variety of formats: www.elastic.co/guide/en/el…
    sourceBuilder.docValueField(field, "use_field_mapping");
    Copy the code
  • DDL
    GET /_search
    {
        "query" : {
            "match_all": {}
        },
        "docvalue_fields" : [
            {
                "field": "my_ip_field", 
                "format": "use_field_mapping" 
            },
            {
                "field": "my_date_field",
                "format": "epoch_millis" 
            }
        ]
    }
    Copy the code

Doc value Gets the data

Map<String, DocumentField> map = oneHit.getFields();
DocumentField module = map.get("module");
spanInfo.setModule(module == null ? "" : module.getValue());
Copy the code

Refer to the official documentation www.elastic.co/guide/en/el… www.elastic.co/guide/en/el…