Пустые ведра от ElasticSearch - PullRequest
       0

Пустые ведра от ElasticSearch

0 голосов
/ 22 сентября 2018

Я получаю пустые сегменты из вложенной агрегации.Я ожидаю получить результат всех ключей и вложенных сегментов с их значениями, но независимо от того, как я их нарежу, я всегда получаю пустой набор результатов блока.с использованием упругого v6.2.4 ее шаги для воспроизведения:

PUT aggregation_test
{"settings": {"number_of_shards": 1}}

PUT aggregation_test/_mapping/doc
{
  "properties": {
    "Description": {
      "type": "text"
    },
    "string_attributes": {
      "type": "nested",
      "properties": {
        "key": {"type": "text"},
        "value": {"type": "text"}
      }
    }
  }
}

Затем заполните данными

POST aggregation_test/doc/1
{
  "Description": "one",
  "string_attributes": [
    { "key": "Variant", "value": "Red"},
    { "key": "Variant", "value": "Yellow"},
    { "key": "Variant", "value": "Blue"},
    { "key": "EcoFriendly", "value": "Yes"}
  ]
}

POST aggregation_test/doc/2
{
  "Description": "two",
  "string_attributes": [
    { "key": "Variant", "value": "Red"},
    { "key": "Variant", "value": "Green"},
    { "key": "Variant", "value": "Blue"},
    { "key": "EcoFriendly", "value": "No"}
  ]
}

POST aggregation_test/doc/3
{
  "Description": "three",
  "string_attributes": [
    {"key": "Variant", "value": "Red"},
    {"key": "Variant", "value": "Green"},
    {"key": "Variant", "value": "Blue"}
  ]
}

Вот моя агрегация

GET aggregation_test/_search
{
  "size": 0,
  "aggs": {
    "nested_level": {
      "nested": {
        "path": "string_attributes"
      },
      "aggs": {
        "keyword_field": {
          "terms": {
            "field": "string_attributes.key.keyword"
          }, "aggs": {
            "value_field": {
              "terms": {"field": "string_attributes.value.keyword"}
            }
          }
        }
      }
    }
  }
}

и результат

{
  "hits": {
    "total": 3,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "nested_level": {
      "doc_count": 11,
      "keyword_field": {
        "doc_count_error_upper_bound": 0,
        "sum_other_doc_count": 0,
        "buckets": []
      }
    }
  }
}

Есть идеи, почему я не вижу никакой информации о ведре?

1 Ответ

0 голосов
/ 22 сентября 2018

Глядя на ваш запрос, он нацелен на поля string_attributes.key.keyword и string_attributes.value.keyword, но на основе вашей схемы у него нет поля keyword для key и value.

.измените вашу схему, чтобы добавить туда поле keyword

PUT aggregation_test 
{
  "mappings": {
    "doc": {
      "properties": {
        "Description": {
          "type": "text"
        },
        "string_attributes": {
          "type": "nested",
          "properties": {
            "key": {
              "type": "text",
              "fields": {
                "keyword": { // add this
                  "type": "keyword" // type should be keyword for proper aggregation
                }
              }
            },
            "value": {
              "type": "text",
              "fields": {
                "keyword": { // add this
                  "type": "keyword" 
                }
              }
            }
          }
        }
      }
    }
  }
}

Надеюсь, что это работает

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...