0

I have a simple documents that get inserted by mongodb directly, it look like this:

PUT /office_db/employee/1
{
  "employeeId": "5b5fc605357d0c6",
  "formalName": "mark rose",
  "socialNumber": 2147483647,
  "contact": {
    "name": "dave more",
    "email": "dave@gmail.com",
    "phone": 918493203
  }
}

and I created a multi match query to search on 3 fields:

GET /office_db/employee/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "214748364",
            "fields": [
              "formalName^-1.0",
              "socialNumber^-1.0",
              "contact.phone^-1.0"
            ],
            "type": "phrase_prefix",
            "lenient": "true"
          }
        }
      ]
    }
  }
}

my issue is that if I try to search for prefix of the socialNumber I dont get results, only if I put the whole number I get results. But if I search for prefix of the formalName I get results...is it possible because of the fields types?

this is my mappings:

{
  "office_db": {
    "mappings": {
      "employee": {
        "properties": {
          "contact": {
            "properties": {
              "email": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "name": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "phone": {
                "type": "long"
              }
            }
          },
          "employeeId": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "formalName": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "socialNumber": {
            "type": "long"
          }
        }
      }
    }
  }
}

I cant change the types really, does someone know what should I fix in the query in order for it to give me results for prefix of the numeric values?

Ninja
  • 85
  • 7
  • You could add a `prefix` query on the `socialNumber` field in your `should` array. – Val Jul 31 '18 at 06:24
  • @Val can you please give an example in an answer, its might be what im looking for :) – Ninja Jul 31 '18 at 07:30
  • hmm no actually `prefix` queries don't work on numeric types – Val Jul 31 '18 at 07:36
  • @Val so should I change my mongo numeric's that I want to search by to strings? – Ninja Jul 31 '18 at 09:48
  • Ideally you should keep the long field and have a sub-field of type text that you can use to search for prefixes. – Val Jul 31 '18 at 09:57
  • @Val in my mongo I should have extra field..? ```"taxId": Int, "searchTaxId": String```? is that a good practice? cause im using mongo-connector and he just takes my documents directly – Ninja Jul 31 '18 at 10:08

0 Answers0