# Which is the best way to sort data in elastic search

**URL:** https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537
**Category:** Elasticsearch
**Created:** [March 12, 2018, 11:23am UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537 "2018-03-12T11:23:13Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![sunilkumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sunilkumar/32/28675_2.png) [@sunilkumar](https://discuss.elastic.co/u/sunilkumar)
#### Post date: [March 12, 2018, 11:23am UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/1 "2018-03-12T11:23:13Z")

</div>

```
 "sort" : [
    	{ "@timestamp" : {"order" : "asc"}}
    	]

```

When i use timestamp to sort data in order,if 2 datas have the same timestamp i'm not able to get the data in logstash processed order.plz help

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [March 12, 2018, 11:39am UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/2 "2018-03-12T11:39:02Z")

</div>

If you are reading the data using Filebeat, there is an offset parameter provided that describes the position within the file. You should be able to use this as a secondary sorting key to get the correct order.

---

<div class="post-metadata">

### Author: ![sunilkumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sunilkumar/32/28675_2.png) [@sunilkumar](https://discuss.elastic.co/u/sunilkumar)
#### Post date: [March 12, 2018, 11:40am UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/3 "2018-03-12T11:40:41Z")

</div>

I'm not using Filebeat . Is there any other possibility??

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [March 12, 2018, 11:42am UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/4 "2018-03-12T11:42:59Z")

</div>

The Logstash file input does not record this, and there is an [issue](https://github.com/logstash-plugins/logstash-input-file/issues/7) around it that has been open a long time. I would recommend using Filebeat, as this now is the recommended way to read files.

---

<div class="post-metadata">

### Author: ![sunilkumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sunilkumar/32/28675_2.png) [@sunilkumar](https://discuss.elastic.co/u/sunilkumar)
#### Post date: [March 12, 2018, 11:47am UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/5 "2018-03-12T11:47:54Z")

</div>

I'll give it a try. Is there a way we can add unique id's along with grok pattern

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [March 12, 2018, 11:50am UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/6 "2018-03-12T11:50:35Z")

</div>

> [@sunilkumar](#):
>
> Is there a way we can add unique id's along with grok pattern

I do not understand how this relates to the sorting. If it is not related to the sorting and you just want to prevent duplicates, read [this blog post](https://www.elastic.co/blog/logstash-lessons-handling-duplicates).

---

<div class="post-metadata">

### Author: ![sunilkumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sunilkumar/32/28675_2.png) [@sunilkumar](https://discuss.elastic.co/u/sunilkumar)
#### Post date: [March 12, 2018, 11:52am UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/7 "2018-03-12T11:52:32Z")

</div>

My Concern is not regarding duplicate values.I just want the data from elastic search to  
be in the same order as it is in the log file

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [March 12, 2018, 11:53am UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/8 "2018-03-12T11:53:31Z")

</div>

For that you need the offset unless there is some kind of sequence or line number in the log file you can extract and use.

---

<div class="post-metadata">

### Author: ![sunilkumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sunilkumar/32/28675_2.png) [@sunilkumar](https://discuss.elastic.co/u/sunilkumar)
#### Post date: [March 12, 2018, 11:54am UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/9 "2018-03-12T11:54:43Z")

</div>

Thank you very much

---

<div class="post-metadata">

### Author: ![sunilkumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sunilkumar/32/28675_2.png) [@sunilkumar](https://discuss.elastic.co/u/sunilkumar)
#### Post date: [March 12, 2018, 12:57pm UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/10 "2018-03-12T12:57:10Z")

</div>

How to use multiline codec along with beats plugin, its showing an error "Multiline codec with beats input is not supported"?

One more problem is that when i try setting 2 outputs in filebeats.yml file i'm getting an error message "more than one namespace configured accessing 'output' "

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [March 12, 2018, 1:08pm UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/11 "2018-03-12T13:08:40Z")

</div>

Filebeat [has support for multiline processing](https://www.elastic.co/guide/en/beats/filebeat/6.2/multiline-examples.html), and you should always perform multiline processing as close to the source as possible.

---

<div class="post-metadata">

### Author: ![sunilkumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sunilkumar/32/28675_2.png) [@sunilkumar](https://discuss.elastic.co/u/sunilkumar)
#### Post date: [March 12, 2018, 1:12pm UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/12 "2018-03-12T13:12:40Z")

</div>

> [@sunilkumar](#):
>
> One more problem is that when i try setting 2 outputs in filebeats.yml file i'm getting an error message "more than one namespace configured accessing 'output' "

How to fix this?

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [March 12, 2018, 1:13pm UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/13 "2018-03-12T13:13:45Z")

</div>

As far as I know Filebeat only supports a single output. Why do you need more than one?

---

<div class="post-metadata">

### Author: ![sunilkumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sunilkumar/32/28675_2.png) [@sunilkumar](https://discuss.elastic.co/u/sunilkumar)
#### Post date: [March 12, 2018, 1:14pm UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/14 "2018-03-12T13:14:17Z")

</div>

I'm using logstash and elasticsearch .

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [March 12, 2018, 1:15pm UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/15 "2018-03-12T13:15:15Z")

</div>

Why not send all the data through Logstash?

---

<div class="post-metadata">

### Author: ![sunilkumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sunilkumar/32/28675_2.png) [@sunilkumar](https://discuss.elastic.co/u/sunilkumar)
#### Post date: [March 12, 2018, 1:17pm UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/16 "2018-03-12T13:17:11Z")

</div>

I'm using elasticsearch to query the data

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [March 12, 2018, 1:26pm UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/17 "2018-03-12T13:26:01Z")

</div>

What does that have to do with the Filebeat config?

If you configure Filebeat to send all data to Logstash, which will in turn write it to Elasticsearch once it has been processed, you will have the offset field provided when you query your data in Elasticsearch.

---

<div class="post-metadata">

### Author: ![sunilkumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sunilkumar/32/28675_2.png) [@sunilkumar](https://discuss.elastic.co/u/sunilkumar)
#### Post date: [March 12, 2018, 1:30pm UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/18 "2018-03-12T13:30:50Z")

</div>

![Screenshot%20(54)](https://us1.discourse-cdn.com/elastic/original/3X/0/a/0a4bb20c8c5c1b2acf218112fb6cc65fef105a64.png) ![Screenshot%20(55)](https://us1.discourse-cdn.com/elastic/original/3X/f/9/f9495a1e4e2444beedbc0065c84c172b0458c8c8.png) ![Screenshot%20(53)](https://us1.discourse-cdn.com/elastic/original/3X/a/d/adaaf49c4909602513752dc6297057be3f7b401e.png)

I've uploaded screenshots for filebeat.yml ,config file and logstash console.  
As you can see the logstash processing stops after pipelines running message with no further response(Its been like that for some time now)

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [March 12, 2018, 1:34pm UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/19 "2018-03-12T13:34:19Z")

</div>

Have you configured Filebeat to actually process any logs so there is data to send to Logstash? Also please do not post screenshots or images of text when you can copy and paste. Images can be hard to read and are not searchable.

---

<div class="post-metadata">

### Author: ![sunilkumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sunilkumar/32/28675_2.png) [@sunilkumar](https://discuss.elastic.co/u/sunilkumar)
#### Post date: [March 12, 2018, 1:40pm UTC](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537/20 "2018-03-12T13:40:59Z")

</div>

_###################### Filebeat Configuration Example #########################_

_# This file is an example configuration file highlighting only the most common_  
_# options. The filebeat.reference.yml file from the same directory contains all the_  
_# supported options with more comments. You can use it as a reference._  
_#_  
_# You can find the full configuration reference here:_  
_# [https://www.elastic.co/guide/en/beats/filebeat/index.html](https://www.elastic.co/guide/en/beats/filebeat/index.html)_

_# For more available modules and options, please see the filebeat.reference.yml sample_  
_# configuration file._

_#=========================== Filebeat prospectors =============================_

_filebeat.prospectors:_

_# Each - is a prospector. Most options can be set at the prospector level, so_  
_# you can use different prospectors for various configurations._  
_# Below are the prospector specific configurations._

_- type: log_

\_ # Change to true to enable this prospector configuration.\_  
\_ enabled: true\_

\_ # Paths that should be crawled and fetched. Glob based paths.\_  
\_ paths:\_  
\_ - D:\logstash\logstash-6.1.0\bin\testlog.txt\_  
\_ #- c:\programdata\elasticsearch\logs\*\_

\_ # Exclude lines. A list of regular expressions to match. It drops the lines that are\_  
\_ # matching any regular expression from the list.\_  
\_ #exclude\_lines: ['^DBG']\_

\_ # Include lines. A list of regular expressions to match. It exports the lines that are\_  
\_ # matching any regular expression from the list.\_  
\_ #include\_lines: ['^ERR', '^WARN']\_

\_ # Exclude files. A list of regular expressions to match. Filebeat drops the files that\_  
\_ # are matching any regular expression from the list. By default, no files are dropped.\_  
\_ #exclude\_files: ['.gz$']\_

\_ # Optional additional fields. These fields can be freely picked\_  
\_ # to add additional information to the crawled log files for filtering\_  
\_ #fields:\_  
\_ # level: debug\_  
\_ # review: 1\_

\_ ### Multiline options\_

\_ # Mutiline can be used for log messages spanning multiple lines. This is common\_  
\_ # for Java Stack Traces or C-Line Continuation\_

\_ # The regexp Pattern that has to be matched. The example pattern matches all lines starting with [\_  
\_ multiline.pattern: [%{DATA}\_

\_ # Defines if the pattern set under pattern should be negated or not. Default is false.\_  
\_ multiline.negate: false\_

\_ # Match can be set to "after" or "before". It is used to define if lines should be append to a pattern\_  
\_ # that was (not) matched before or after or as long as a pattern is not matched based on negate.\_  
\_ # Note: After is the equivalent to previous and before is the equivalent to to next in Logstash\_  
\_ multiline.match: after\_

_#============================= Filebeat modules ===============================_

_filebeat.config.modules:_  
\_ # Glob pattern for configuration loading\_  
\_ path: ${path.config}/modules.d/\*.yml\_

\_ # Set to true to enable config reloading\_  
\_ reload.enabled: false\_

\_ # Period on which files under path should be checked for changes\_  
\_ #reload.period: 10s\_

_#==================== Elasticsearch template setting ==========================_

_setup.template.settings:_  
\_ index.number\_of\_shards: 3\_  
\_ #index.codec: best\_compression\_  
\_ #_source.enabled: false_

_#================================ General =====================================_

_# The name of the shipper that publishes the network data. It can be used to group_  
_# all the transactions sent by a single shipper in the web interface._  
_#name:_

_# The tags of the shipper are included in their own field with each_  
_# transaction published._  
_#tags: ["service-X", "web-tier"]_

_# Optional fields that you can specify to add additional information to the_  
_# output._  
_#fields:_  
_# env: staging_

_#============================== Dashboards =====================================_  
_# These settings control loading the sample dashboards to the Kibana index. Loading_  
_# the dashboards is disabled by default and can be enabled either by setting the_  
_# options here, or by using the `-setup` CLI flag or the `setup` command._  
_#setup.dashboards.enabled: false_

_# The URL from where to download the dashboards archive. By default this URL_  
_# has a value which is computed based on the Beat name and version. For released_  
_# versions, this URL points to the dashboard archive on the [artifacts.elastic.co](http://artifacts.elastic.co)_  
_# website._  
_#setup.dashboards.url:_

_#============================== Kibana =====================================_

_# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API._  
_# This requires a Kibana endpoint configuration._  
_setup.kibana:_

\_ # Kibana Host\_  
\_ # Scheme and port can be left out and will be set to the default (http and 5601)\_  
\_ # In case you specify and additional path, the scheme is required: [http://localhost:5601/path\_](http://localhost:5601/path_)  
\_ # IPv6 addresses should always be defined as: https://[2001:db8::1]:5601\_  
\_ #host: "localhost:5601"\_

_#============================= Elastic Cloud ==================================_

_# These settings simplify using filebeat with the Elastic Cloud ([https://cloud.elastic.co/](https://cloud.elastic.co/))._

_# The cloud.id setting overwrites the `output.elasticsearch.hosts` and_  
_# `setup.kibana.host` options._  
_# You can find the `cloud.id` in the Elastic Cloud web UI._  
_#cloud.id:_

_# The cloud.auth setting overwrites the `output.elasticsearch.username` and_  
_# `output.elasticsearch.password` settings. The format is `<user>:<pass>`._  
_#cloud.auth:_

_#================================ Outputs =====================================_

_# Configure what output to use when sending the data collected by the beat._

_#-------------------------- Elasticsearch output ------------------------------_  
_#output.elasticsearch:_  
\_ # Array of hosts to connect to.\_  
\_ # hosts: ["localhost:9200"]\_

\_ # Optional protocol and basic auth credentials.\_  
\_ #protocol: "https"\_  
\_ #username: "elastic"\_  
\_ #password: "changeme"\_

_#----------------------------- Logstash output --------------------------------_  
_output.logstash:_  
\_ # The Logstash hosts\_  
\_ hosts: ["localhost:5044"]\_

\_ # Optional SSL. By default is off.\_  
\_ # List of root certificates for HTTPS server verifications\_  
\_ #ssl.certificate\_authorities: ["/etc/pki/root/ca.pem"]\_

\_ # Certificate for SSL client authentication\_  
\_ #ssl.certificate: "/etc/pki/client/cert.pem"\_

\_ # Client Certificate Key\_  
\_ #ssl.key: "/etc/pki/client/cert.key"\_

_#================================ Logging =====================================_

_# Sets log level. The default log level is info._  
_# Available log levels are: critical, error, warning, info, debug_  
_#logging.level: debug_

_# At debug level, you can selectively enable logging only for some components._  
_# To enable all selectors use ["\*"]. Examples of other selectors are "beat",_  
_# "publish", "service"._  
_#logging.selectors: ["\*"]_

I think i've configured it correctly and the problem might be with sinceDB because i saw the response once

[Next page](https://discuss.elastic.co/t/which-is-the-best-way-to-sort-data-in-elastic-search/123537.md?page=2)
