@sghosh001c
I would use ingest node because you are sending your data directly to Elasticsearch.
Walkthrough
Here's a working solution that I tested on Elasticsearch 6.3.0.
This solution will work only if you can do three things:
- Set
node.ingest: true
in the elasticsearch.yml files your nodes (or at least one of them).
- Create an ingest pipeline (see Step 1 below).
- Reference the ID of your pipeline (see Step 2 below) as your data is sent from PCF to Elasticsearch.
Regarding (3), you said that "In Pivotal CF, we mentioned elasticsearch url as the syslog drain url." I haven't worked with PCF enough to judge if it's possible to reference a pipeline in that URL. If it isn't possible, then I would recommend directing your data from PCF to Logstash instead of to Elasticsearch, and using a Logstash pipeline instead of an ingest pipeline.
Assuming you can do these three things, let's take a look at how that would work.
Step 1: Create the ingest pipeline.
Let's create an ingest pipeline called pcf_pipeline
. We'll apply three processors in this pipeline:
- We'll use the
grok
processor to extract the JSON object that's embedded in your syslog_msg
string and put it in a new field called syslog_msg_payload
.
- We'll use the
json
processor to parse our newly extracted syslog_msg_payload
field into a JSON object.
- We'll use the
remove
processor to drop our temporary field syslog_msg_payload
.
Query:
PUT _ingest/pipeline/pcf_pipeline
{
"description": "PCF Pipeline",
"processors": [
{
"grok": {
"field": "syslog_msg",
"patterns": [ "%{JSON:syslog_msg_payload}" ],
"pattern_definitions": {
"JSON": "{.*$"
},
"ignore_missing": true
}
},
{
"json": {
"field": "syslog_msg_payload",
"target_field": "syslog_msg_json"
}
},
{
"remove": {
"field": "syslog_msg_payload"
}
}
]
}
Step 2: Index a document.
Let's put in a sample document. You must include the pipeline=pcf_pipeline
parameter in your URL. Otherwise your ingest pipeline will not be triggered.
Query:
PUT pcf_index/_doc/1?pipeline=pcf_pipeline
{
"syslog5424_ver": 1,
"pid": "[APP/PROC/WEB/0]",
"@timestamp": "2018-11-01T13:15:55.578Z",
"priority": 14,
"syslog5425_len": 584,
"program": "990c27da-8eed-4872-bad5-0a8feab39a4a",
"host": "69.241.18.11",
"syslog_msg": "2018-11-01 13:15:33.911 INFO 24 --- [nio-8080-exec-6] c.s.a.c.InventoryOrderController : {\"serverName\":\"0c9663d6-ca18-4ac2-7b5e-1cc9\",\"eventComponent\":\"/cpa/orders/status/pending\",\"eventName\":\"getOrdersByStatus/Request\",\"executionTime\":\"Thu Nov 01 13:15:33 UTC 2018\",\"executedBy\":\"enterprise\",\"eventId\":\"b60fe79f-5884-4778-bdd5-c20e6a7afacd\",\"eventType\":\"API/Info\",\"serverIp\":\"10.10.82.186\",\"eventDetails\":\"/cpa/orders/status/pending\"}",
"logsource": "BSDSIGMADEV.API.InventoryOrderMicroService",
"@version": "1",
"syslog5424_msgid": "-"
}
Step 3: View the indexed document.
Let's see what how our ingest pipeline affected the document. Notice that your embedded JSON string has been copied into structured fields, which you can now query directly. Success!
Query:
GET pcf_index/_doc/1
Response:
{
"_index": "pcf_index",
"_type": "_doc",
"_id": "1",
"_version": 4,
"found": true,
"_source": {
"syslog_msg_json": {
"executionTime": "Thu Nov 01 13:15:33 UTC 2018",
"executedBy": "enterprise",
"eventId": "b60fe79f-5884-4778-bdd5-c20e6a7afacd",
"eventDetails": "/cpa/orders/status/pending",
"serverName": "0c9663d6-ca18-4ac2-7b5e-1cc9",
"eventName": "getOrdersByStatus/Request",
"serverIp": "10.10.82.186",
"eventComponent": "/cpa/orders/status/pending",
"eventType": "API/Info"
},
"pid": "[APP/PROC/WEB/0]",
"syslog5425_len": 584,
"syslog5424_ver": 1,
"program": "990c27da-8eed-4872-bad5-0a8feab39a4a",
"priority": 14,
"logsource": "BSDSIGMADEV.API.InventoryOrderMicroService",
"syslog5424_msgid": "-",
"@timestamp": "2018-11-01T13:15:55.578Z",
"host": "69.241.18.11",
"@version": "1",
"syslog_msg": """2018-11-01 13:15:33.911 INFO 24 --- [nio-8080-exec-6] c.s.a.c.InventoryOrderController : {"serverName":"0c9663d6-ca18-4ac2-7b5e-1cc9","eventComponent":"/cpa/orders/status/pending","eventName":"getOrdersByStatus/Request","executionTime":"Thu Nov 01 13:15:33 UTC 2018","executedBy":"enterprise","eventId":"b60fe79f-5884-4778-bdd5-c20e6a7afacd","eventType":"API/Info","serverIp":"10.10.82.186","eventDetails":"/cpa/orders/status/pending"}"""
}
}