Home > Mobile >  "Search as you type" and elasticsearch
"Search as you type" and elasticsearch

Time:01-05

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 28 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 28 ??

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

Regards

I expected the results to contain both BLAKER AND 28

CodePudding user response:

With two clausules multi_match I get the result.

 {
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "BLAKER",
            "type": "bool_prefix",
            "fields": [
              "street",
              "street._2gram",
              "street._3gram"
            ]
          }
        },
        {
          "multi_match": {
            "query": "28",
            "type": "bool_prefix",
            "fields": [
              "street",
              "street._2gram",
              "street._3gram"
            ]
          }
        }
      ]
    }
  }
}

Hits:

"hits": [
  {
    "_index": "idx_test",
    "_id": "5DN7fIUBQB-6H-4ZZKWL",
    "_score": 2,
    "_source": {
      "street": "BLAKERVEIEN 288A"
    }
  }
]
  • Related