tryingHard
tryingHard

Reputation: 2104

Match exactly query in Kibana demo

I am testing default demo of Kibana: Dashboard [eCommerce] Revenue Dashboard. When I filter from [eCommerce] Controls, for example, setting the category to Men's Accessories I see other categories on [eCommerce] Sales by Category. How can I change that?

I see that the query is built like:

{
  "query": {
    "match": {
      "category.keyword": {
        "query": "Men's Accessories",
        "type": "phrase"
      }
    }
  }
}

So this translates to:

 "query": {
    "bool": {
      "must": [
        {
          "match_phrase": {
            "category.keyword": {
              "query": "Men's Accessories"
            }
          }
        },

How can I change this demo to show exactly the category that I selected?

Example screen: enter image description here

EDIT:

I'm not looking for some silly solution - that work one time. I want to show only one category - but with one filter - not one filter and for example three negation. If i change my category to another - put it simply i chose "women's shoes" i want to show only that category from applying only this one filter that i chosed from the dashboard - not some custom made filter by typing some words. I want to make visualization that when applied shows excatly one category - not 4 like right now.

EDIT: I created two documents (with brand new Men's TEST_NEW_CATEGORY) in Kibana Dev Tools section with this:

POST kibana_sample_data_ecommerce/_doc/
{
    "category": [
      "Men's TEST_NEW_CATEGORY"
    ],
    "currency": "EUR",
    "customer_first_name": "Youssef",
    "customer_full_name": "Youssef Jensen",
    "customer_gender": "MALE",
    "customer_id": 31,
    "customer_last_name": "Jensen",
    "customer_phone": "",
    "day_of_week": "Saturday",
    "day_of_week_i": 5,
    "email": "youssef@jensen-family.zzz",
    "manufacturer": [
      "Low Tide Media"
    ],
    "order_date": "2019-05-15T23:45:36+00:00",
    "order_id": 592109,
    "products": [
      {
        "base_price": 49.99,
        "discount_percentage": 0,
        "quantity": 1,
        "manufacturer": "Low Tide Media",
        "tax_amount": 0,
        "product_id": 12202,
        "category": "Men's TEST_NEW_CATEGORY",
        "sku": "ZO0396603966",
        "taxless_price": 49.99,
        "unit_discount_amount": 0,
        "min_price": 26.49,
        "_id": "sold_product_592109_12202",
        "discount_amount": 0,
        "created_on": "2016-12-31T23:45:36+00:00",
        "product_name": "Moccasins - stone",
        "price": 49.99,
        "taxful_price": 49.99,
        "base_unit_price": 49.99
      },
      {
        "base_price": 28.99,
        "discount_percentage": 0,
        "quantity": 1,
        "manufacturer": "Low Tide Media",
        "tax_amount": 0,
        "product_id": 15017,
        "category": "Men's Clothing",
        "sku": "ZO0452704527",
        "taxless_price": 28.99,
        "unit_discount_amount": 0,
        "min_price": 13.63,
        "_id": "sold_product_592109_15017",
        "discount_amount": 0,
        "created_on": "2016-12-31T23:45:36+00:00",
        "product_name": "Jumper - off-white",
        "price": 28.99,
        "taxful_price": 28.99,
        "base_unit_price": 28.99
      }
    ],
    "sku": [
      "ZO0396603966",
      "ZO0452704527"
    ],
    "taxful_total_price": 78.98,
    "taxless_total_price": 78.98,
    "total_quantity": 2,
    "total_unique_products": 2,
    "type": "order",
    "user": "youssef",
    "geoip": {
      "country_iso_code": "US",
      "location": {
        "lon": -74,
        "lat": 40.8
      },
      "region_name": "New York",
      "continent_name": "North America",
      "city_name": "New York"
    }
}

Then i clearly see that there is only one category when using standard filter button:

enter image description here

Upvotes: 0

Views: 316

Answers (2)

Polynomial Proton
Polynomial Proton

Reputation: 5135

If you want to filter by a specific category, you would want to use filter instead of terms. Terms aggregation will be applied on all the values in the field. Also, notice that i disabled terms aggregation using toggle. I'm using only filter for the use case you mentioned

You can set it up like below: Filter by One Category

You can also add multiple filters like below:

multiple filters

Another option is add a scripted field and visualize on those scripted fields, but this case is pretty straight forward i.e. from one field so that is not required. However, when collating data from several fields - scripted fields can be useful.

Updated Answer :

The demo is restrictive, you cannot change the data or play around with analyzers. But in reality you can filter out an array by exact match for a value you want and then apply the filter.

For now, if you filter the array using dev tools in kibana you will see it returns all documents where it matches your category - it may or may not have extra categories but it will always have what you are looking for.

hence, when you add a filter you still see other categories in visualization since thats how the data is.

kibana query

Upvotes: 1

Jin Lee
Jin Lee

Reputation: 3522

This is how I solved it. I had to use 4 filters only to see Men's Clothing.

enter image description here

The image might be too small to recognize, so I will write them down.

The first filter :

{
"query": {
  "match": {
    "category.keyword": {
       "query": "Men's Clothing",
        "type": "phrase"
    }
   }
  }
 }

The second filter:

{
   "query": {
     "match": {
       "category.keyword": {
          "query": "Women's Accessories",
          "type": "phrase"
        }
       }
      }
     }

The third filter:

{
    "query": {
       "match": {
          "category.keyword": {
             "query": "Men's Shoes",
             "type": "phrase"
             }
           }
         }
       }

The fourth filter:

{
   "query": {
     "match": {
     "category.keyword": {
        "query": "Men's Accessories",
         "type": "phrase"
       }
      }
    }
  }

I don't know why but if I view the query as DSL it doesn't show "is not" operator. so let me show you an image of "is not" operator.

enter image description here

Then, you will see all the dashboard only with one category like below.

enter image description here

Now I just realized you only wanted to see men's accessory not men's clothing. My poor eyesight. However, I hope you got a rough idea. If you want, I can do men's clothing. Let me know. Btw, I tried to do it with just one filter but somehow the graph wouldn't work.

Upvotes: 0

Related Questions