# Can we use wildcard in the field\_name or Can we apply condition in fields block inside query\_string

**URL:** https://discuss.elastic.co/t/can-we-use-wildcard-in-the-field-name-or-can-we-apply-condition-in-fields-block-inside-query-string/308904
**Category:** Elasticsearch
**Created:** [July 5, 2022, 11:56am UTC](https://discuss.elastic.co/t/can-we-use-wildcard-in-the-field-name-or-can-we-apply-condition-in-fields-block-inside-query-string/308904 "2022-07-05T11:56:30Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![deepak\_prem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deepak_prem/32/107756_2.png) [@deepak\_prem](https://discuss.elastic.co/u/deepak_prem)
#### Post date: [July 5, 2022, 11:56am UTC](https://discuss.elastic.co/t/can-we-use-wildcard-in-the-field-name-or-can-we-apply-condition-in-fields-block-inside-query-string/308904/1 "2022-07-05T11:56:30Z")

</div>

Hi friends, I have the following questions related to the Elasticsearch:-

1. I want to know Can we use the **wildcard in the fields name in term block** in the query, if not is there any alternate way to achieve this.like In the below query I want to achieve something like this.

````auto
    "must": [
                {
                  "term": {
                    "*_sold.Type": "Type XYZ"
                  }
                }
        ]
  }```

````

1. How we can apply condition in **"fields"** in **query\_string** block. e.g I have this part of query I want that if type of attribute is Type XYZ then only we need to search into this attribute.

```auto
{
          "query_string": {
            "query": "data",
            "type": "best_fields",
            "fields": [
              "date",
              "id_number",
              "type",
              "*__Sold.*" // here I want that if "*_Sold.Type" == "Type XYZ" then only seach inside this attributes otherwise skip it.  
            ],
            "lenient": true,
            "default_operator": "AND",
            "boost": 3
          }

}

```

**Here is the sample document.**

```auto
    {
            "_index" : "_dev",
            "_type" : "_doc",
            "_id" : "data-2",
            "_score" : 1.0,
            "_source" : {
              "type" : "datas",
              "id_number" : 736762732784934,
              "date" : "2011-01-26",
              "Service_Sold" : [
                {
                  "Type" : "Type XYZ",
                  "Service_Name" : "Service XYZ"
                }
              ],
              "Product_Sold" : [
                {
                  "Type" : "Type ABC",
                  "Product_Name" : "Product ABC"
                }
              ]
              "Item_Sold" : [
                {
                  "Type" : "Type XYZ",
                  "Item_Name" : "Item XYZ"
                }
              ]
              ...
              50 other attributes
  }

```

Would appreciate any suggestions and help.

Note:- 7.10 version elastic-seach running queries on KIBANA. We can also upgrade our verison if required.

---

<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: [August 2, 2022, 11:56am UTC](https://discuss.elastic.co/t/can-we-use-wildcard-in-the-field-name-or-can-we-apply-condition-in-fields-block-inside-query-string/308904/2 "2022-08-02T11:56:59Z")

</div>

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