# Why term query not returning the document that contains the exact term in 7.3.2

**URL:** <https://discuss.elastic.co/t/why-term-query-not-returning-the-document-that-contains-the-exact-term-in-7-3-2/284540>\
**Category:** Elasticsearch\
**Created:** [September 18, 2021, 10:54am UTC](https://discuss.elastic.co/t/why-term-query-not-returning-the-document-that-contains-the-exact-term-in-7-3-2/284540 "2021-09-18T10:54:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lee\_Copper](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lee_copper/32/94746_2.png) [@Lee\_Copper](https://discuss.elastic.co/u/Lee_Copper)\
**Post date:** [September 18, 2021, 10:54am UTC](https://discuss.elastic.co/t/why-term-query-not-returning-the-document-that-contains-the-exact-term-in-7-3-2/284540/1 "2021-09-18T10:54:51Z")

</div>

I have a order\_no with value '100000076268946605' in my index.  
The following term query does not return me the document with order\_no '100000076268946605':

```auto
{
  "query": {
          "term": {
            "order_no": {
              "value": "100000076268946605"
            }
          }
  }
}

```

The term query find another document like this:

```auto
{ - 
  "took": 2,
  "timed_out": false,
  "_shards": { - 
    "total": 2,
    "successful": 2,
    "skipped": 0,
    "failed": 0
  },
  "hits": { - 
    "total": { - 
      "value": 1,
      "relation": "eq"
    },
    "max_score": 14.483531,
    "hits": [ - 
      { - 
        "_index": "trans_drp_experience_store_service_order",
        "_type": "_doc",
        "_id": "1438331557453504524",
        "_score": 14.483531,
        "_source": { - 
          "activity_amt": "",
          "buyer_name": "tLddgedggieda1dlaxg==",
          "buyer_phone": "Yghzx1rfi4pchdfdfedfdgdfdaf",
          "code_value": "866028053541177",
          "coupon_amt": "0.0",
          "data_source": "1",
          "etl_time": "2021-09-18 18:15:01.127",
          "is_booking": "no",
          "is_gift": "no",
          "member_amt": "0.0",
          "online_order_send_way": "10",
          "order_detail_id": 1438331557453504500,
          "order_detail_status": "",
          "order_no": 100000076268946610,
          "order_type": "10",
          "price_adjustment_amt": "",
          "product_amt": "1799.0",
          "product_category_name": "",
          "product_final_amt": "1799.0",
          "product_name": "phone",
          "product_qty": "1",
          "product_retail_amt": "1799.0",
          "sale_time": "2021-09-16 10:41:05",
          "saler_name": "",
          "shop_name": "",
          "sku_code": "110010331209",
          "sku_name": "",
          "source": "SALE ORDER",
          "spu_name": "",
          "unit": ""
        }
      }
    ]
  }
}

```

The term query return the document contains order\_no with value '100000076268946610'.  
'100000076268946605'

My index settings like this:

```auto
{ - 
  "trans_drp_experience_store_service_order": { - 
    "settings": { - 
      "index": { - 
        "refresh_interval": "1s",
        "number_of_shards": "2",
        "provided_name": "trans_drp_experience_store_service_order",
        "creation_date": "1631958631725",
        "number_of_replicas": "2",
        "uuid": "ax6vbL6RShGjfvcPXqLOxw",
        "version": { - 
          "created": "7030299"
        }
      }
    }
  }
}

mappings
{ - 
  "trans_drp_experience_store_service_order": { - 
    "mappings": { - 
      "dynamic_templates": [ - 
        { - 
          "strings_not_analyzed": { - 
            "match_mapping_type": "string",
            "mapping": { - 
              "type": "keyword"
            }
          }
        }
      ],
      "properties": { - 
        "activity_amt": { - 
          "type": "keyword"
        },
        "buyer_name": { - 
          "type": "keyword"
        },
        "buyer_phone": { - 
          "type": "keyword"
        },
        "code_value": { - 
          "type": "keyword"
        },
        "coupon_amt": { - 
          "type": "keyword"
        },
        "data_source": { - 
          "type": "keyword"
        },
        "etl_time": { - 
          "type": "keyword"
        },
        "is_booking": { - 
          "type": "keyword"
        },
        "is_gift": { - 
          "type": "keyword"
        },
        "member_amt": { - 
          "type": "keyword"
        },
        "online_order_send_way": { - 
          "type": "keyword"
        },
        "order_detail_id": { - 
          "type": "keyword"
        },
        "order_detail_status": { - 
          "type": "keyword"
        },
        "order_no": { - 
          "type": "keyword"
        },
        "order_type": { - 
          "type": "keyword"
        },
        "price_adjustment_amt": { - 
          "type": "keyword"
        },
        "product_amt": { - 
          "type": "keyword"
        },
        "product_category_name": { - 
          "type": "keyword"
        },
        "product_final_amt": { - 
          "type": "keyword"
        },
        "product_name": { - 
          "type": "keyword"
        },
        "product_qty": { - 
          "type": "keyword"
        },
        "product_retail_amt": { - 
          "type": "keyword"
        },
        "sale_time": { - 
          "type": "keyword"
        },
        "saler_name": { - 
          "type": "keyword"
        },
        "shop_name": { - 
          "type": "keyword"
        },
        "sku_code": { - 
          "type": "keyword"
        },
        "sku_name": { - 
          "type": "keyword"
        },
        "source": { - 
          "type": "keyword"
        },
        "spu_name": { - 
          "type": "keyword"
        },
        "unit": { - 
          "type": "keyword"
        }
      }
    }
  }
}

```

I am confused why term query does not return the desired document.

---

<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:** [September 18, 2021, 1:31pm UTC](https://discuss.elastic.co/t/why-term-query-not-returning-the-document-that-contains-the-exact-term-in-7-3-2/284540/2 "2021-09-18T13:31:26Z")

</div>

Numbers in JSON has finite precision so it would be better if you stored the order number as a string.

---

<div class="post-metadata">

**Author:** ![tmp13](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tmp13/32/78005_2.png) [@tmp13](https://discuss.elastic.co/u/tmp13)\
**Post date:** [September 19, 2021, 11:43am UTC](https://discuss.elastic.co/t/why-term-query-not-returning-the-document-that-contains-the-exact-term-in-7-3-2/284540/3 "2021-09-19T11:43:03Z")

</div>

Hi.  
Can you find document with order\_no "100000076268946605" using another filter?  
And show it in reply.

P.S Simple answer on your question - it doesn`t exist=))

---

<div class="post-metadata">

**Author:** ![Lee\_Copper](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lee_copper/32/94746_2.png) [@Lee\_Copper](https://discuss.elastic.co/u/Lee_Copper)\
**Post date:** [September 22, 2021, 2:05am UTC](https://discuss.elastic.co/t/why-term-query-not-returning-the-document-that-contains-the-exact-term-in-7-3-2/284540/4 "2021-09-22T02:05:12Z")

</div>

It's weird. My dynamic templates make map all fields only as `keyword`s

---

<div class="post-metadata">

**Author:** ![Lee\_Copper](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lee_copper/32/94746_2.png) [@Lee\_Copper](https://discuss.elastic.co/u/Lee_Copper)\
**Post date:** [September 22, 2021, 2:21am UTC](https://discuss.elastic.co/t/why-term-query-not-returning-the-document-that-contains-the-exact-term-in-7-3-2/284540/5 "2021-09-22T02:21:57Z")

</div>

I tried several other filter, but it still not work .

```auto
{
  "query": {
    "match": {
      "order_no": {
        "query": "100000076268946605"
      }
    }
  }
}

```

same result

```auto
{ - 
  "took": 12,
  "timed_out": false,
  "_shards": { - 
    "total": 2,
    "successful": 2,
    "skipped": 0,
    "failed": 0
  },
  "hits": { - 
    "total": { - 
      "value": 1,
      "relation": "eq"
    },
    "max_score": 14.183976,
    "hits": [ - 
      { - 
        "_index": "trans_drp_experience_store_service_order",
        "_type": "_doc",
        "_id": "1438331557453504524",
        "_score": 14.183976,
        "_source": { - 
          "activity_amt": "",
          "buyer_name": "tLddgedggieda1dlaxg==",
          "buyer_phone": "Yghzx1rfi4pchdfdfedfdgdfdaf",
          "code_value": "866028053541177",
          "coupon_amt": "0.0",
          "data_source": "1",
          "etl_time": "2021-09-18 19:38:04.536",
          "is_booking": "n",
          "is_gift": "n",
          "member_amt": "0.0",
          "online_order_send_way": "10",
          "order_detail_id": 1438331557453504500,
          "order_detail_status": "",
          "order_no": 100000076268946610,
          "order_type": "10",
          "price_adjustment_amt": "",
          "product_amt": "1799.0",
          "product_category_name": "",
          "product_final_amt": "1799.0",
          "product_name": "",
          "product_qty": "1",
          "product_retail_amt": "1799.0",
          "sale_time": "2021-09-16 10:41:05",

```

index 10192510 documents, Only order\_no "100000076268946605“ can not work.

---

<div class="post-metadata">

**Author:** ![tmp13](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tmp13/32/78005_2.png) [@tmp13](https://discuss.elastic.co/u/tmp13)\
**Post date:** [September 22, 2021, 7:24am UTC](https://discuss.elastic.co/t/why-term-query-not-returning-the-document-that-contains-the-exact-term-in-7-3-2/284540/6 "2021-09-22T07:24:44Z")

</div>

heh=)  
I mean find this document using filter without order\_no, may be you can find it using another fields.

Because now it look like order\_no 100000076268946605 doesn`t exist in your index.

---

<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:** [October 20, 2021, 7:25am UTC](https://discuss.elastic.co/t/why-term-query-not-returning-the-document-that-contains-the-exact-term-in-7-3-2/284540/7 "2021-10-20T07:25:02Z")

</div>

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