Elasticsearch: Is it possible to query for a term facet that contains more than a term

StackOverflow https://stackoverflow.com/questions/19302388

  •  30-06-2022
  •  | 
  •  

Question

Part of my mapping looks like this:

{
  ...
  INFO_NODO: {
    properties: {
      CODIGO: {
        type: string
      }
      ESTADO: {
        type: string
      }
      IN_HOME: {
        type: string
      }
      TEXTO: {
        type: string
      }
      ID_NODO: {
        type: integer
      }
      ...
    }
  }
}

I need to make a facet that will return the fields: ID_NODO, TEXTO, IN_HOME, ESTADO, CODIGO, and COUNT to parse it and feed it to my application. The key is that all these fields except COUNT are dependant on the ID_NODO, that is, if the field INFO_NODO is the same the rest of the information is the same... with that being said ideally I would like to make my facet dependent on the whole INFO_NODO field and not its sub-fields. I found several solutions but I keep either failing to implement them properly or they are just not working. Any thoughts on my weird situation?

EDIT: What I'd need to do is:

{
  "facets": {
    "FACET_X_NODO": {
      "terms": {
        "field": "INFO_NODO"
      }
    }
  }
}

I just can't get the syntax in no documentation since INFO_NODO is a subdocument and not a field.

Was it helpful?

Solution

If I understood you correctly, you should be able to do something like this:

{
    "query" : {
        "match_all" : {  }
    },
    "facets" : {
        "info_node_facet" : {
            "terms" : {
                "script_field" : "_source.INFO_NODO.CODIGO + _source.INFO_NODO.ESTADO",
                "size" : 10
            }
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top