Term Query is not working


(Giorgi Kharchenko) #1

Hi,
I tried to run this query.
but this query is not working.
I changed term with match_phrase so it is working.
Can you tell me what the problem is?

GET index/_search
   {
      "query": {
        "bool": {
          "must": [
            {
              "nested": {
                "path": "identifiers",
                "query": {
                  "bool": {
                    "must": [
                      {
                        "term": {
                          "identifiers.value": "PERSONAS"
                        }
                      }
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    }

(David Pilato) #2

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.


(Giorgi Kharchenko) #4

This is the query I built
But it is not working
I am not sure why it is not working, I tried with match_phrase . so it is working.
Can you help me ?


Match Query - Can you help me?
(Christian Dahlqvist) #5

Please provide all the relevant information in a recreation script and describe exactly what is not working. Having access to sample data and mappings together with the query makes it a lot easier to help.

Also please do not open multiple threads for the same issue. It is a lot easier if all the information can be found in the same place. It looks to me like the following threads refer to the same issue, is that correct?

Also note that this forum is manned by volunteers, so please be patient. It may take some time for someone to respond, and if you have not received any response in a couple work business days it is generally OK to bump the thread.


(Giorgi Kharchenko) #6
{
  "_index": "organization",
  "_type": "entry",
  "_id": "ttuBjWYB0npV7oenbMnB",
  "_version": 1,
  "_score": 6.3722887,
  "_source": {
    "dim_tags": [
      "ORGU"
    ],
    "identifiers": [
      {
        "value": "List",
        "key": "List"
      },
      {
        "value": "SCHANDY",
        "key": "Nivel 1"
      },
      {
        "value": "PUERTOS",
        "key": "Nivel 2"
      },
      {
        "value": "MONTECON ADMINISTRACION COMPRAS PERSONAS COMERCIAL",
        "key": "Nivel 3"
      }
    ],
    "was_edited_proper_names": "No",
    "TI_WG_Score": 18.97,
    "TI_ORG_Score": 18.97,
    "demographics": [
      {
        "value": "Atención al Cliente",
        "key": "Tipo de Cargo que Ocupa"
      },
      {
        "value": "Ventas / Comercial",
        "key": "Área de Trabajo"
      },
      {
        "value": "Femenino",
        "key": "Sexo"
      },
      {
        "value": "35 a 44 años",
        "key": "Edad"
      },
      {
        "value": "6 a 10 años",
        "key": "Antigüedad en la Empresa"
      },
      {
        "value": "Post grado",
        "key": "Nivel educacional"
      },
      {
        "value": "Montevideo",
        "key": "Lugar de Trabajo"
      },
      {
        "value": "Contrato indefinido (NO a plazo)",
        "key": "Relación Laboral"
      }
    ],
    "TI_AVG_Score": 18.97,
    "question": "¿Hay algo único o especial de su empresa que la hace ser un gran lugar para trabajar? Dar ejemplos específicos.",
    "edited_names": [],
    "id": "JMYPPBPAHB",
    "organization_id": 37918,
    "was_excluded": "No",
    "original_response": "'Al margen de lo subjetivo de cada uno de nosotros y de como vemos a la empresa, todos somos empleados que trabajamos con altos niveles de ética. Por otro lado lo que para mi hace especial a esta empresa son mis compañeros de trabajo y por compañeros me refiero a quienes estamos en el mismo nivel. A todos nos han logrado unir las diferencias que se hacen dependiendo del cargo que se ocupa (se promueven siempre a los mismos, bonificaciones, etc) y es por ello que de lo \"malo\" sale lo bueno.'",
    "survey_id": "Schandy_Jul2018",
    "edited_response": "'Al margen de lo subjetivo de cada uno de nosotros y de como vemos a la empresa, todos somos empleados que trabajamos con altos niveles de ética. Por otro lado lo que para mi hace especial a esta empresa son mis compañeros de trabajo y por compañeros me refiero a quienes estamos en el mismo nivel. A todos nos han logrado unir las diferencias que se hacen dependiendo del cargo que se ocupa (se promueven siempre a los mismos, bonificaciones, etc) y es por ello que de lo \"malo\" sale lo bueno.'"
  },
  "highlight": {
    "organization_id": [
      "@kibana-highlighted-field@37918@/kibana-highlighted-field@"
    ]
  }
}

This is one of the data.
I want to get data by identifiers.value.
If I type a word in a input, it will return data if one of identifiers.value is input word.

so if I put "PERSONAS", the sample data will not be returned.
but if I put "MONTECON ADMINISTRACION COMPRAS PERSONAS COMERCIAL", the sample data will be returned.
For this, I built query I posted before.
But the query is not working.
Instead of "term", I used "match_phrase" but it is returning sample data (it is wrong)


(David Pilato) #7

Yes probably. If you provide what I asked for, then I can try to reproduce and help.


(Giorgi Kharchenko) #8

What do you need?


(David Pilato) #9

What do you need?

You did not read my answer? I'm copying here the relevant part.