# "Search as you type" and elasticsearch

**URL:** <https://discuss.elastic.co/t/search-as-you-type-and-elasticsearch/322438>\
**Category:** Elasticsearch\
**Created:** [January 4, 2023, 9:05am UTC](https://discuss.elastic.co/t/search-as-you-type-and-elasticsearch/322438 "2023-01-04T09:05:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rhh](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@Rhh](https://discuss.elastic.co/u/Rhh)\
**Post date:** [January 4, 2023, 9:05am UTC](https://discuss.elastic.co/t/search-as-you-type-and-elasticsearch/322438/1 "2023-01-04T09:05:00Z")

</div>

Hi

I have a text field with the type set to "search as you type". When I request data I get all data corresponding to BLAKER OR 288 in the street field.

( the street field contains the streetname + house number )

But how can I only get data corresponding to names starting with BLAKER AND house numbers starting with 288 ??

```auto
http://localhost:9200/xxx-2023.01/_search
{
  "query": {
    "multi_match": {
      "query": "BLAKER 288",
      "type": "bool_prefix",
      "fields": [
        "street",
        "street._2gram",
        "street._3gram"
      ]
    }
  }
}

```

I get results like the one below

```auto
     "hits": [
            {
                "_index": "tds-address-2023.01",
                "_type": "_doc",
                "_id": "O10peIUBAPhS0x2BjjMG",
                "_score": 1.0,
                "_source": {
                    "@timestamp": "2023-01-03T16:04:26.9587963+01:00",
                    "level": "Information",
                    "centralcode": null,
                    "area1": {
                        "number": "30",
                        "name": "VIKEN"
                    },
                    "area2": {
                        "number": "3030",
                        "name": "LILLESTRØM"
                    },
                    "area3": {
                        "number": "",
                        "name": ""
                    },
                    "post": {
                        "number": "1925",
                        "name": "BLAKER"
                    },
                    "city": "BLAKER",
                    "street": "BLAKERVEIEN 288A",
                    "location": "u68j2b"
                }
            },
            {
                "_index": "tds-address-2023.01",
                "_type": "_doc",
                "_id": "sV0peIUBAPhS0x2BkTi3",
                "_score": 1.0,
                "_source": {
                    "@timestamp": "2023-01-03T16:04:27.4872962+01:00",
                    "level": "Information",
                    "centralcode": null,
                    "area1": {
                        "number": "30",
                        "name": "VIKEN"
                    },
                    "area2": {
                        "number": "3030",
                        "name": "LILLESTRØM"
                    },
                    "area3": {
                        "number": "",
                        "name": ""
                    },
                    "post": {
                        "number": "1925",
                        "name": "BLAKER"
                    },
                    "city": "BLAKER",
                    "street": "FJUKVEIEN 288",
                    "location": "u68j6f"
                }
            },
            {
                "_index": "tds-address-2023.01",
                "_type": "_doc",
                "_id": "-l0peIUBAPhS0x2BqF6x",
                "_score": 1.0,
                "_source": {
                    "@timestamp": "2023-01-03T16:04:32.9391556+01:00",
                    "level": "Information",
                    "centralcode": null,
                    "area1": {
                        "number": "18",
                        "name": "NORDLAND"
                    },
                    "area2": {
                        "number": "1838",
                        "name": "GILDESKÅL"
                    },
                    "area3": {
                        "number": "",
                        "name": ""
                    },
                    "post": {
                        "number": "8130",
                        "name": "SANDHORNØY"
                    },
                    "city": "SANDHORNØY",
                    "street": "SANDHORNØYVEIEN 288",
                    "location": "u7fjcp"
                }
            },
            {
                "_index": "tds-address-2023.01",
                "_type": "_doc",
                "_id": "z10peIUBAPhS0x2Brm38",
                "_score": 1.0,
                "_source": {
                    "@timestamp": "2023-01-03T16:04:35.2106261+01:00",
                    "level": "Information",
                    "centralcode": null,
                    "area1": {
                        "number": "18",
                        "name": "NORDLAND"
                    },
                    "area2": {
                        "number": "1875",
                        "name": "HÁBMER"
                    },
                    "area3": {
                        "number": "",
                        "name": ""
                    },
                    "post": {
                        "number": "8294",
                        "name": "HAMARØY"
                    },
                    "city": "HAMARØY",
                    "street": "BUVÅGVEIEN 288",
                    "location": "uk5583"
                }
            },
            {
                "_index": "tds-address-2023.01",
                "_type": "_doc",
                "_id": "cV0peIUBAPhS0x2BvoEI",
                "_score": 1.0,
                "_source": {
                    "@timestamp": "2023-01-03T16:04:38.0302645+01:00",
                    "level": "Information",
                    "centralcode": null,
                    "area1": {
                        "number": "30",
                        "name": "VIKEN"
                    },
                    "area2": {
                        "number": "3003",
                        "name": "SARPSBORG"
                    },
                    "area3": {
                        "number": "",
                        "name": ""
                    },
                    "post": {
                        "number": "1747",
                        "name": "SKJEBERG"
                    },
                    "city": "SKJEBERG",
                    "street": "GRESSDALVEIEN 288",
                    "location": "u4xbw6"
                }
            },

```

I wanted only the first with BLAKERVEIEN 288A.

When I use the and operator it gives no results.

```auto
http://localhost:9200/xxx-2023.01/_search
{
  "query": {
    "multi_match": {
      "query": "BLAKER 288",
      "operator": "and", 
      "type": "bool_prefix",
      "fields": [
        "street",
        "street._2gram",
        "street._3gram"
      ]
    }
  }
}

```

Any help on this ?

Regards

---

<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:** [February 1, 2023, 9:05am UTC](https://discuss.elastic.co/t/search-as-you-type-and-elasticsearch/322438/2 "2023-02-01T09:05:35Z")

</div>

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