Search code examples
elasticsearchcachingelasticsearch-6

ElasticSearch - How to search by type?


I've put an item into ElasticSearch with given index and type. How do I retrieve it?

Details:

The official documentation states this:

GET /_search
{
    "query": {
        "type" : {
            "value" : "_doc"
        }
    }
}

But I don't get it. What do I do with that?

I tried to run it like this but it didn't work:

curl XGET 'http://localhost:9200/disney/_search' -d '
{
    "query": {
        "type" : {
            "value" : "disneytype"
        }
    }
}'

This throws an error:

Invoke-WebRequest : A positional parameter cannot be found that accepts argument
'http://localhost:9200/disney/_search'.
At line:1 char:1
+ curl XGET 'http://localhost:9200/disney/_search' -d '
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Any ideas how to run it properly?


Solution

  • The error that you've got is not related to Elasticsearch. It is some issue with PowerShell. Replace cURL call with Invoke-WebRequest:

    Invoke-WebRequest -Method 'POST' -Uri 'http://localhost:9200/_search' -ContentType "application/json" -Body '
    {
      "query": {
        "type": {
          "value": "disneytype"
        }
      }
    }'
    

    I personally prefer to use Kibana for discovering my ES indices. It is much more convenient.