0
{
  "stage_video_clip_646f4c0fb780630373dfffdb" : {
    "mappings" : {
      "date_detection" : false,
      "properties" : {
        "@class" : {
          "type" : "keyword"
        },
        "additionalProperties" : {
          "properties" : {
            "@class" : {
              "type" : "keyword"
            },
            "eventId" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "linius:offset" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "opta:eventId" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "videoOffset" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
        "assetCreated" : {
          "type" : "long"
        },
        "assetEndDate" : {
          "type" : "long"
        },
        "assetId" : {
          "type" : "keyword"
        },
        "assetStartDate" : {
          "type" : "long"
        },
        "created" : {
          "type" : "long"
        },
        "endTime" : {
          "type" : "long"
        },
        "id" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "payload" : {
          "type" : "nested",
          "properties" : {
            "@class" : {
              "type" : "keyword"
            },
            "additionalProperties" : {
              "properties" : {
                "@class" : {
                  "type" : "keyword"
                }
              }
            },
            "category" : {
              "type" : "keyword"
            },
            "clipId" : {
              "type" : "keyword"
            },
            "confidence" : {
              "type" : "double"
            },
            "endTime" : {
              "type" : "long"
            },
            "indexerType" : {
              "type" : "keyword"
            },
            "integerValue" : {
              "type" : "long"
            },
            "payloadId" : {
              "type" : "keyword"
            },
            "payloadValueSuggest" : {
              "type" : "completion",
              "analyzer" : "standard",
              "preserve_separators" : true,
              "preserve_position_increments" : true,
              "max_input_length" : 10000
            },
            "startTime" : {
              "type" : "long"
            },
            "suggestCategory" : {
              "type" : "completion",
              "analyzer" : "standard",
              "preserve_separators" : true,
              "preserve_position_increments" : true,
              "max_input_length" : 10000
            },
            "suggestValueCategory" : {
              "type" : "completion",
              "analyzer" : "standard",
              "preserve_separators" : true,
              "preserve_position_increments" : true,
              "max_input_length" : 10000,
              "contexts" : [
                {
                  "name" : "category-context",
                  "type" : "CATEGORY",
                  "path" : "payload.category"
                }
              ]
            },
            "value" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
        "startTime" : {
          "type" : "long"
        },
        "tenantId" : {
          "type" : "keyword"
        },
        "updated" : {
          "type" : "long"
        }
      }
    }
  }
}

This is the mapping of document in elasticsearch , I want to fetch the disctinct list of payload.value on the basis of search the string over payload.category

For example , there is 2 documents

{ docId:1 "payload": [ { "category": "YEAR", "value": "2012" }, { "category": "YEAR", "value": "2014" }, { "category": "match", "value": "aus vs india" } ] }

{ docId:2 "payload": [ { "category": "YEAR", "value": "2012" }, { "category": "YEAR", "value": "2019" } ] }

Now i want to fetch the payload.value unique elements on the basis of payload.category that is YEAR , so ES should return the 2012,2019,2014 so these are the disctinct list that need to be reutrned captured from all documents

1 Answers1

1

you can have the itens hits with inner hits.

{
  "query": {
    "nested": {
      "path": "payload",
      "query": {
        "term": {
          "payload.category": {
            "value": "YEAR"
          }
        }
      },
      "inner_hits": {}
    }
  }
}
rabbitbr
  • 2,991
  • 2
  • 4
  • 17