How to get all document ids (_id) in a specific index

I am trying to get all documents in the index, only getting the _id field.

Basically I want to get all the document IDs I have.

Using:

{
   "query": {
       "match_all": {}
   },
   "fields": []
}

      

The hits I get are: "_index", "_type", "_id", "_score", "_source" which is more than I need.

Edit (answer) : So my problem was that I was using KOPF to run queries and the results were inaccurate (got the _source and a few more)! I got correct results when using curl!

So the above query actually achieved what I needed! You can also use:

{
   "query": {
      "match_all": {}
   },
   "_source": false,
}

      

or

{
   "query": {
      "match_all": {}
   },
   "fields": ["_id"]
}

      

+3


source to share


2 answers


For elasticsearch , only special fields can be used _source

using an array fields

.

_index

, _type

, _id

, _score

It must be returned elasticsearch .



there is no way to remove them from the answer.

+6


source


I am assuming your _id has your document in the index not in the index itself.

In the newer version of vertical search, "_source" is used to retrieve the selected fields of your es document, because the _source fields contain everything you need to find elastic es records.

Example:

Let's say the index name is "movies" and the type is "movie" and you want to get the name movieName and movieTitle of all elastic search records.



curl -XGET 'http://localhost:9200/movies/movie/_search?pretty=true' -d '
{ 
    "query" : { 
        "match_all" : {} 
    },
    "_source": ["movieName","movieTitle"]
}'

      

OR http: // localhost: 9200 / movies / movie / _search? Pretty = true & _source = movieName, movieTitle

By default, it returns 10 results. To get n number of posts, then put & size = n in url

0


source







All Articles