简体   繁体   中英

How to make Elasticsearch date_histogram facet work on nested items

I am using Kibana 3 to query my Elasticsearch server. Kibana offers a date_histogram visualization panel to display prices that I have gathered for products. Each product can contain an arbitrary amount of prices with an according date. Prices are implemented as nested fields within each document.

Kibana creates the below query which works fine when applied to all documents.

curl -XGET 'http://localhost.com:9200/vendor2/_search?pretty' -d '{
  "facets": {
    "1": {
      "date_histogram": {
        "key_field": "Prices.Fetched",
        "value_field": "Prices.Price",
        "interval": "1m"
      },
      "nested": "Prices",
      "facet_filter": {
        "fquery": {
          "query": {
            "filtered": {
              "query": {
                "query_string": {
                  "query": "*"
                }
              },
              "filter": {
                "bool": {
                  "must": [
                    {
                      "match_all": {}
                    },
                    {
                      "bool": {
                        "must": [
                          {
                            "match_all": {}
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "size": 0
}'

The problem comes up, when I try to use the date_histogram to visualize price movements over time for a single product. Kibana offers the ability to filter down to a certain document. For example based on its id/sku.

However, then the date_histogram facet stays empty.

This is an example... Can anyone please advise what could be wrong with the query?

curl -XGET 'http://localhost.com:9200/vendor2/_search?pretty' -d '{   "facets": {
    "1": {
      "date_histogram": {
        "key_field": "Prices.Fetched",
        "value_field": "Prices.Price",
        "interval": "1m"
      },
      "nested": "Prices",
      "facet_filter": {
        "fquery": {
          "query": {
            "filtered": {
              "query": {
                "query_string": {
                  "query": "*"
                }
              },
              "filter": {
                "bool": {
                  "must": [
                    {
                      "match_all": {}
                    },
                    {
                      "fquery": {
                        "query": {
                          "field": {
                            "sku": {
                              "query": "\"AZF78FH77\""
                            }
                          }
                        },
                        "_cache": true
                      }
                    },
                    {
                      "bool": {
                        "must": [
                          {
                            "match_all": {}
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }   },   "size": 0 }'

The problem is the double quotes that you have included in your query (notice the escaped quotes in the query). This will cause ElasticSearch to look for SKUs of '"AZF78FH77"', rather than 'AZF78FH77'

Try querying in Kibana without quotes in the query box.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM