# How to make query output data format in 1 string

**URL:** <https://discuss.elastic.co/t/how-to-make-query-output-data-format-in-1-string/104159>\
**Category:** Elasticsearch\
**Created:** [October 17, 2017, 2:11am UTC](https://discuss.elastic.co/t/how-to-make-query-output-data-format-in-1-string/104159 "2017-10-17T02:11:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joyce\_Feng](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@Joyce\_Feng](https://discuss.elastic.co/u/Joyce_Feng)\
**Post date:** [October 17, 2017, 2:11am UTC](https://discuss.elastic.co/t/how-to-make-query-output-data-format-in-1-string/104159/1 "2017-10-17T02:11:27Z")

</div>

In ES2.2, the output source is 1 single line/string:  
"hits" : [ {  
"\_index" : "ise",  
"\_type" : "contextrepo",  
"\_id" : "da:d8:54:41:ee:23",  
"\_score" : 1.0,  
"\_source":{"AuthenticationMethod":"Wired","AuthorizationPolicyMatchedRule":"Default","SelectedAuthorizationProfiles":"Dot1X","AuthenticationIdentityStore":"InternalUser","Description":"description7499628","Email":"emailid153048@rediff.com","EndPointPolicy":"XeroxWorkCentre7556","FirstName":"fname9494","IdentityGroup":"Engineering","ip":"250.64.136.241","ipv6":"9feb:7ec8:3e6c:2a97::9","LastName":"lname75739","LogicalProfile":"GamingDevices","MACAddress":"da:d8:54:41:ee:23","MDMCompliant":"noncompliant","MDMDiskEncrypted":"true","MDMJailBroken":"false","MDMPinLockSet":"true","mdmRegistrationStatus":"false","Location":"locations#alllocations#ntn#ntn10","OUI":"da:d8:54","PostureStatus":"unknown","status":"Connected","PortalUser":"portaluser56880","userName":"user103124","NetworkDeviceName":"ntn10NAD456908","StaticAssignment":"Yes","StaticGroupAssignment":"Yes","FailureReason":"Reason Code: 15455","User-Fetch-Department":"ABC-3","User-Fetch-Telephone":"19","User-Fetch-Job-Title":"ENG-3","User-Fetch-Organizational-Unit":"SAMPG-8","User-Fetch-CountryName":"USA-12","User-Fetch-LocalityName":"LOC-4","User-Fetch-StateOrProvinceName":"CA-2","User-Fetch-StreetAddress":"STR-8","UserType":"Guest-Sponsor","PortalUserGuestSponsor":"Desk Admin 1","PortalUserGuestType":"Contractor","PhoneID":"UDID3697091"}}

But in 5.2, the output is multiple line:  
{  
"\_index" : "ise",  
"\_type" : "contextrepo",  
"\_id" : "f5:6e:ca:11:ed:f5",  
"\_score" : 1.0,  
"\_source" : {  
"AuthenticationMethod" : "Wireless",  
"AuthorizationPolicyMatchedRule" : "Default",  
"SelectedAuthorizationProfiles" : "Dot1X",  
"AuthenticationIdentityStore" : "Internal User",  
"Description" : "description9496862",  
"Email" : "emailid104970@rediff.com",  
"EndPointPolicy" : "Cisco-AIR-AP-1250",  
"FirstName" : "fname19454",  
"IdentityGroup" : "HR",  
"ip" : "43.20.3.32",  
"ipv6" : "44ae:1430:27a5:10bc::9",  
"LastName" : "lname97497",  
"LogicalProfile" : "Medical Devices",  
"MACAddress" : "f5:6e:ca:11:ed:f5",  
"MDMDiskEncrypted" : "true",  
"MDMJailBroken" : "true",  
"MDMPinLockSet" : "true",  
"mdmRegistrationStatus" : "false",  
"Location" : "locations#all locations#bxb#bxb2",  
"OUI" : "f5:6e:ca",  
"PostureStatus" : "non-compliant",  
"status" : "Connected",

How to make 5.5.2 output same as 2.4 data to be 1 string?

the command I used:  
curl -k -XGET "[http://localhost:9200/ise/tableindex/\_search?pretty](http://localhost:9200/ise/tableindex/_search?pretty)"

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 17, 2017, 2:24am UTC](https://discuss.elastic.co/t/how-to-make-query-output-data-format-in-1-string/104159/2 "2017-10-17T02:24:52Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

Remove `?pretty` and you should be ok.

---

<div class="post-metadata">

**Author:** ![Joyce\_Feng](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@Joyce\_Feng](https://discuss.elastic.co/u/Joyce_Feng)\
**Post date:** [October 17, 2017, 2:56am UTC](https://discuss.elastic.co/t/how-to-make-query-output-data-format-in-1-string/104159/3 "2017-10-17T02:56:19Z")

</div>

Remove pretty will combine all the output in one line, in ES2.4 each output is still a separate item, just the source part is one single line. I'd still like each output to be separated, but the source part to be one string.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 17, 2017, 5:59am UTC](https://discuss.elastic.co/t/how-to-make-query-output-data-format-in-1-string/104159/4 "2017-10-17T05:59:55Z")

</div>

Normally we don’t prettify the \_source and we just present it as it was sent to elasticsearch. Apparently we do now.

You can’t have finer control I’m afraid.

pretty=true is made for humans  
pretty=false is made for computers

What is your use case that would require a mix of that?

---

<div class="post-metadata">

**Author:** ![Joyce\_Feng](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@Joyce\_Feng](https://discuss.elastic.co/u/Joyce_Feng)\
**Post date:** [October 17, 2017, 6:22am UTC](https://discuss.elastic.co/t/how-to-make-query-output-data-format-in-1-string/104159/5 "2017-10-17T06:22:56Z")

</div>

I have some perl scripts parsing the curl output data into Json, then use the Json file to do bulk import into new database.

The 5.5.2 export format broke the perl script, so I am wondering if there is some parameters to set to keep the 2.4 curl output format, or else I will fix the perl script.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 17, 2017, 9:24am UTC](https://discuss.elastic.co/t/how-to-make-query-output-data-format-in-1-string/104159/6 "2017-10-17T09:24:13Z")

</div>

I just double checked and indeed when you use pretty in 5.6 we are prettifying also the `_source` field.

With:

```auto
DELETE test
PUT test/doc/1
{"foo":"bar"}
PUT test/doc/2
{
  
  "foo": "bar"

  
}

```

```auto
$ curl -XGET "http://localhost:9200/test/_search?pretty"

```

Gives

```json
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test",
        "_type" : "doc",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "foo" : "bar"
        }
      },
      {
        "_index" : "test",
        "_type" : "doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "foo" : "bar"
        }
      }
    ]
  }
}

```

And

```auto
$ curl -XGET "http://localhost:9200/test/_search"

```

Gives

```json
{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":2,"max_score":1.0,"hits":[{"_index":"test","_type":"doc","_id":"2","_score":1.0,"_source":{
  
  "foo": "bar"

  
}
},{"_index":"test","_type":"doc","_id":"1","_score":1.0,"_source":{"foo":"bar"}
}]}}

```

I'd not use pretty at all when the content is supposed to be parsed by a script.

---

<div class="post-metadata">

**Author:** ![Joyce\_Feng](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@Joyce\_Feng](https://discuss.elastic.co/u/Joyce_Feng)\
**Post date:** [October 17, 2017, 4:10pm UTC](https://discuss.elastic.co/t/how-to-make-query-output-data-format-in-1-string/104159/7 "2017-10-17T16:10:22Z")

</div>

Thanks!

Is there any option to not prettify all the others but not prettify the source field?  
ES2.4 behaves like that.

---

<div class="post-metadata">

**Author:** ![Joyce\_Feng](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@Joyce\_Feng](https://discuss.elastic.co/u/Joyce_Feng)\
**Post date:** [October 17, 2017, 4:11pm UTC](https://discuss.elastic.co/t/how-to-make-query-output-data-format-in-1-string/104159/8 "2017-10-17T16:11:06Z")

</div>

Is there any option to prettify all the others **but not** prettify the source field?  
ES2.4 behaves like that.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 17, 2017, 4:27pm UTC](https://discuss.elastic.co/t/how-to-make-query-output-data-format-in-1-string/104159/9 "2017-10-17T16:27:26Z")

</div>

I don't think there is.

Again, pretty is meant for humans. Not pretty is meant for computers.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 14, 2017, 4:28pm UTC](https://discuss.elastic.co/t/how-to-make-query-output-data-format-in-1-string/104159/10 "2017-11-14T16:28:02Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
