# Elasticsearch across all fields with fuzzy and wildcard searching

**URL:** <https://discuss.elastic.co/t/elasticsearch-across-all-fields-with-fuzzy-and-wildcard-searching/123529>\
**Category:** Elasticsearch\
**Created:** [March 12, 2018, 11:03am UTC](https://discuss.elastic.co/t/elasticsearch-across-all-fields-with-fuzzy-and-wildcard-searching/123529 "2018-03-12T11:03:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![palaniichukdmytro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/palaniichukdmytro/32/28755_2.png) [@palaniichukdmytro](https://discuss.elastic.co/u/palaniichukdmytro)\
**Post date:** [March 12, 2018, 11:03am UTC](https://discuss.elastic.co/t/elasticsearch-across-all-fields-with-fuzzy-and-wildcard-searching/123529/1 "2018-03-12T11:03:52Z")

</div>

I use elasticsearch to match all fields in the query when typing text in the input field. I use query\_string to match all fields that match a search value with a wildcard( search for any word that starts with search value ${search}\*). when I want to search all field that contains cancel word and start with one letter c it works when I am typing two letter ca nothing matched, and again when I am typing three letters can it matched all cancel fields. Also How to avoid some characters and spaces (/, \_, -) etc.

**query**

```
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 26,
    "max_score": 1,
    "hits": [
      {
        "_index": "call",
        "_type": "Call",
        "_id": "IP319mEBHPDr8pMVG_zn",
        "_score": 1,
        "_source": {
          "type": "type",
          "location": "location",
          "zone": "zone",
          "personName": "person_name",
          "personRoom": "person_room",
          "cancelPerson": "cancel_person",
          "cancelLocation": "cancel_location"
        }
      },
      {
        "_index": "call",
        "_type": "Call",
        "_id": "LP0V_GEBHPDr8pMVHfzb",
        "_score": 1,
        "_source": {
          "type": "Call",
          "zone": "22"
        }
      },
      {
        "_index": "call",
        "_type": "Call",
        "_id": "M_2GGWIBHPDr8pMVpPyx",
        "_score": 1,
        "_source": {
          "timestamp": {
            "seconds": "1520846631",
            "nanos": 638962100
          },
          "type": "Wandering",
          "location": "Room_222",
          "zone": "Zone_220",
          "personName": "First_Name_226 Last_Name_226 ",
          "personRoom": "Room_222",
          "cancelTimestamp": {
            "seconds": "1520846677",
            "nanos": 103338000
          },
          "responseTime": {
            "seconds": "45",
            "nanos": 464375900
          }
        }
      },
    ]
  }
}

```

**ES search**

```
export const get = ({index, skip = 0, pageSize = defaultPageSize, search, sort}) => new Promise(async resolve => {
        try {
            logger.silly(`getting data from elastic: index: ${index}, skip: ${skip}, pageSize: ${pageSize}`)

            let client = createClient()

            console.log(sort, 'sort')

            const params = {
                from: skip,
                size: pageSize || undefined,
                index: index.toLowerCase(),
                filter_path: 'hits.hits._source, hits.total',
            }

            if (search) {
                // params.q = `${search}*`
                params.body = {
                    query :{
                        'query_string': {
                            'query': `${search}*`,
                        },
                    },
                }
            }

            await client.search(params,
                (e, {hits: {hits: data = [], total: totalCount} = {hits: [], total: 0}} = {}) => {

                    logger.silly(`elastic searching completed. Result: contains ${totalCount} items`)
                    console.log(data, 'data ')

                    resolve({items: data.map(t => t._source), totalCount})
                })
        } catch (e) {
            logger.error(e)
        }
    })
```

---

<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:** [April 9, 2018, 11:03am UTC](https://discuss.elastic.co/t/elasticsearch-across-all-fields-with-fuzzy-and-wildcard-searching/123529/2 "2018-04-09T11:03:57Z")

</div>

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