# Accessing non document fields ElasticSearch Filter

**URL:** <https://discuss.elastic.co/t/accessing-non-document-fields-elasticsearch-filter/183844>\
**Category:** Logstash\
**Created:** [June 2, 2019, 2:26am UTC](https://discuss.elastic.co/t/accessing-non-document-fields-elasticsearch-filter/183844 "2019-06-02T02:26:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Summers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/james_summers/32/47285_2.png) [@James\_Summers](https://discuss.elastic.co/u/James_Summers)\
**Post date:** [June 2, 2019, 2:26am UTC](https://discuss.elastic.co/t/accessing-non-document-fields-elasticsearch-filter/183844/1 "2019-06-02T02:26:49Z")

</div>

In converting some custom ruby code to run as a logstash pipeline, I added an elasticsearch filter pipeline, I'm able to do the query but am unable to access the sort field from the elasticsearch result.

The Filter:

```auto
	elasticsearch {
		hosts => ["http://elasticsearch:9200"]
		index => "location"
		query_template => "query.json"
		fields => {
			"country_name" => "[geodata][country]"
			"country_code" => "[geodata][country_code]"
			"region_name" => "[geodata][region]"
			"admin1_code" => "[geodata][region_code]"
			"name" => "[geodata][city]"
			"population" => "[geodata][population]"
			"[sort][0]" => "[geodata][distance_km]"
		}
	}  

```

The query:

```auto
{
	"size" : 1,
	"query" : { "bool" : { "filter" : [ 
				{ "term" : { "feature_class" : "P" } },
				{ "range" : { "population" : { "gt" : 0 } } },
				{ "geo_distance" : { 
						"distance" : "1000km",
						"location" : {
							"lat" : "%{[location][1]}",
							"lon" : "%{[location][0]}"
						}
					}
				}
			]
		}
	},
	"sort" : [
		{ 
			"_geo_distance" : {
				"location" : { 
					"lat" : "%{[location][1]}",
					"lon" : "%{[location][0]}"
				}, 
				"unit" : "km"
			}
		}
	]
}

```

The result for an example:

```auto
{
  "took" : 9,
  "timed_out" : false,
  "_shards" : {
    "total" : 3,
    "successful" : 3,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 293,
    "max_score" : null,
    "hits" : [
      {
        "_index" : "geonames-2018-11-25_reindex",
        "_type" : "_doc",
        "_id" : "af-0TGcB_qrwk1wisyv6",
        "_score" : null,
        "_source" : {
          "geonameid" : "5859888",
          "name" : "Cordova",
          "asciiname" : "Cordova",
          "alternatenames" : [
            "CDV",
            "Kordova",
            "ke er duo wa",
            "kodoba",
            "kordobha",
            "kwrdwfa",
            "kwrdwwa alaska",
            "Кордова",
            "كوردوفا",
            "کوردووا، آلاسکا",
            "कोर्दोभा",
            "コードバ",
            "科尔多瓦"
          ],
          "latitude" : 60.5432,
          "longitude" : -145.75867,
          "feature_class" : "P",
          "feature_code" : "PPL",
          "country_code" : "US",
          "cc2" : [],
          "admin1_code" : "AK",
          "admin2_code" : "261",
          "population" : 2196,
          "elevation" : 29,
          "dem" : -9999,
          "timezone" : "America/Anchorage",
          "modification_date" : "2017-06-12",
          "location" : [
            -145.75867,
            60.5432
          ],
          "feature_name" : "populated place",
          "region_name" : "Alaska",
          "admin2" : "Valdez-Cordova Census Area",
          "country_name" : "United States"
        },
        "sort" : [
          202.01066621324418
        ]
      }
    ]
  }
}

```

I'm attempting to add the "sort" value to the resultant document and not sure of the exact syntax.

---

<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:** [June 30, 2019, 2:26am UTC](https://discuss.elastic.co/t/accessing-non-document-fields-elasticsearch-filter/183844/2 "2019-06-30T02:26:53Z")

</div>

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