# Term Query is not working

**URL:** <https://discuss.elastic.co/t/term-query-is-not-working/158470>\
**Category:** Elasticsearch\
**Created:** [November 28, 2018, 6:12am UTC](https://discuss.elastic.co/t/term-query-is-not-working/158470 "2018-11-28T06:12:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giorgi\_Kharchenko](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@Giorgi\_Kharchenko](https://discuss.elastic.co/u/Giorgi_Kharchenko)\
**Post date:** [November 28, 2018, 6:12am UTC](https://discuss.elastic.co/t/term-query-is-not-working/158470/1 "2018-11-28T06:12:45Z")

</div>

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?

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

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 28, 2018, 6:27am UTC](https://discuss.elastic.co/t/term-query-is-not-working/158470/2 "2018-11-28T06:27:16Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) 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:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

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](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). 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.

---

<div class="post-metadata">

**Author:** ![Giorgi\_Kharchenko](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@Giorgi\_Kharchenko](https://discuss.elastic.co/u/Giorgi_Kharchenko)\
**Post date:** [November 28, 2018, 6:38am UTC](https://discuss.elastic.co/t/term-query-is-not-working/158470/4 "2018-11-28T06:38:25Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [November 28, 2018, 7:07am UTC](https://discuss.elastic.co/t/term-query-is-not-working/158470/5 "2018-11-28T07:07:12Z")

</div>

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?

> [@Term Query issue](https://discuss.elastic.co/t/term-query-issue/158464):
>
> Hi, all { "query": { "bool": { "must": [{ "nested": { "path": "identifiers", "query": { "bool": { "must": [{ "term": { "identifiers.value": "PERSONAS" } }] } } } } ] } } } I am not sure why this query is not working

> [@Match Query - Can you help me?](https://discuss.elastic.co/t/match-query-can-you-help-me/158457):
>
> Hi, I want to search this kind of thing. I have fields like this. identifiers:[{key: "list1", value:"My name is Giorgi"}, {key:"list2", value:"Giorgi"}, {key:"list3", value:"Giorgi Kharchenko"}] { "query" :{ "bool" :{ "must" : { "match\_phrase" :{ "identifiers.value" : "Giorgi" } } } } } } So I want to get records which contains identifiers that includes search value for value property. {key:"list2", value:"Giorgi"} I am not sure how I can build th…

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.

---

<div class="post-metadata">

**Author:** ![Giorgi\_Kharchenko](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@Giorgi\_Kharchenko](https://discuss.elastic.co/u/Giorgi_Kharchenko)\
**Post date:** [November 28, 2018, 7:17am UTC](https://discuss.elastic.co/t/term-query-is-not-working/158470/6 "2018-11-28T07:17:39Z")

</div>

```auto
{
  "_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)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 28, 2018, 7:36am UTC](https://discuss.elastic.co/t/term-query-is-not-working/158470/7 "2018-11-28T07:36:31Z")

</div>

> [@Giorgi\_Kharchenko](#):
>
> Can you help me ?

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

---

<div class="post-metadata">

**Author:** ![Giorgi\_Kharchenko](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@Giorgi\_Kharchenko](https://discuss.elastic.co/u/Giorgi_Kharchenko)\
**Post date:** [November 28, 2018, 7:37am UTC](https://discuss.elastic.co/t/term-query-is-not-working/158470/8 "2018-11-28T07:37:41Z")

</div>

What do you need?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 28, 2018, 7:55am UTC](https://discuss.elastic.co/t/term-query-is-not-working/158470/9 "2018-11-28T07:55:19Z")

</div>

> What do you need?

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

> [@dadoonet](#):
>
> Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). 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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 26, 2018, 7:56am UTC](https://discuss.elastic.co/t/term-query-is-not-working/158470/10 "2018-12-26T07:56:03Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
