# Flatting Libpostal label / value response

**URL:** <https://discuss.elastic.co/t/flatting-libpostal-label-value-response/122355>\
**Category:** Logstash\
**Created:** [March 3, 2018, 6:51am UTC](https://discuss.elastic.co/t/flatting-libpostal-label-value-response/122355 "2018-03-03T06:51:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johnnycc1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johnnycc1/32/26069_2.png) [@Johnnycc1](https://discuss.elastic.co/u/Johnnycc1)\
**Post date:** [March 3, 2018, 6:52am UTC](https://discuss.elastic.co/t/flatting-libpostal-label-value-response/122355/1 "2018-03-03T06:52:00Z")

</div>

Ok so I'm using a libpostal rest interface to parse out some addresses that our systems have captured --\> [here](https://github.com/johnlonganecker/libpostal-rest-docker) is the docker image.

Basically I submit in a request like this

> curl -X POST -d '{"query": "100b sydney st buffalo ny"}' localhost:8080/parser | python -mjson.tool

And i get a response like this - the number of label/value pairs depends on the format and length of the address (sometimes there is multiple of the same label for compound addresses).

> ```
> [
> {
> "label": "house_number",
> "value": "100b"
> },
> {
> "label": "road",
> "value": "sydney st"
> },
> {
> "label": "city",
> "value": "buffalo"
> },
> {
> "label": "state",
> "value": "ny"
> }
> ]
> 
> ```

Using the [http filter plugin](https://github.com/lucashenning/logstash-filter-rest) in logstash I can submit millions of requests to this API. However the response is not that useful cause it is a nested object of labels and values. Below is the http filter plugin usage.

> rest {  
> request =\> {  
> url =\> "[http://xxxxx.net:8080/parser](http://xxxxx.net:8080/parser)"  
> method =\> "post"  
> params =\> {  
> "query" =\> "%{address}"  
> }  
> }  
> json =\> true  
> target =\> "addressParsed"  
> }

I would like to process the response in logstash to look more like this --\>

> ```
> [
> {
> "house_number" : "100b",
> "road" : "sydney st", 
> "city" : "buffalo",
> "state":"ny"
> }
> ]
> 
> ```

I think that this is what the kv filter is meant to help me out with (however not really sure).  
I have been experimenting around with the a logstash config that looks something like this without any luck --\>

```
kv {
allow_duplicate_values => true
source => "%{addressParsed}"
target => "addressKV"
recursive => "true"
field_split => ","
value_split => ":"
include_brackets => false
}

```

Can somebody confirm that I am heading the in right direction ?

---

<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:** [March 31, 2018, 6:52am UTC](https://discuss.elastic.co/t/flatting-libpostal-label-value-response/122355/2 "2018-03-31T06:52:03Z")

</div>

Closed on March 31, 2018, 6:52am UTC

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