Exploring Your Data

Exploring Your Data

Sample Dataset

Now that we’ve gotten a glimpse of the basics, let’s try to work on a more realistic dataset.

I’ve prepared a sample of fictitious JSON documents of customer bank account information.

Each document has the following schema:

{
    "account_number": 0, "balance": 16623, "firstname": "Bradshaw", "lastname": "Mckenzie", "age": 29, "gender": "F", "address": "244 Columbus Place", "employer": "Euron", "email": "[email protected]", "city": "Hobucken", "state": "CO" }

For the curious, this data was generated using www.json-generator.com/, so please ignore the actual values and semantics of the data as these are all randomly generated.

Loading the Sample Dataset

You can download the sample dataset (accounts.json) from here.

Extract it to our current directory and let’s load it into our cluster as follows:

curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_doc/_bulk?pretty&refresh" --data-binary "@accounts.json" curl "localhost:9200/_cat/indices?v"

And the response:

health status index uuid                   pri rep docs.count docs.deleted store.size pri.store.size yellow open bank l7sSYV2cQXmu6_4rJWVIww 5 1 1000 0 128.6kb 128.6kb

 Which means that we just successfully bulk indexed 1000 documents into the bank index (under the _doc type).

The Search API

Now let’s start with some simple searches.

There are two basic ways to run searches:

one is by sending search parameters through the REST request URI 

and the other by sending them through the REST request body.

The request body method allows you to be more expressive and also to define your searches in a more readable JSON format.

We’ll try one example of the request URI method but for the remainder of this tutorial, we will exclusively be using the request body method.

The REST API for search is accessible from the _search endpoint.

This example returns all documents in the bank index:

猜你喜欢

转载自www.cnblogs.com/chucklu/p/10556882.html