user5616242
user5616242

Reputation:

PHP Elasticsearch: wildcard query won't find any results

Im trying to use a wildcard for a specific column in my elasticsearch document. However, doing so, nothing happens. Elasticsearch doesn't find any results.

Source: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html

How my search query looks like:

array:3 [
  "index" => "certificates"
  "type" => "_doc"
  "body" => array:3 [
    "from" => 0
    "size" => 25
    "query" => array:1 [
      "wildcard" => array:1 [
        "product_name" => array:1 [
          "value" => "Fra*"
        ]
      ]
    ]
  ]
]

I don't see any difference to what the elasticsearch documentation recommends me.

PHP Version: 7.1.3

Elasticsearch version: 6.7.0

Response from elasticsearch when searching:

{
    "took": 2,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 0,
        "max_score": null,
        "hits": []
    }
}

Sample data inside of a document:

enter image description here

Upvotes: 1

Views: 281

Answers (1)

user5616242
user5616242

Reputation:

Didn't solve it with wildcards--still not working--however, it works with query_string

            'query_string' => [
                'query' => 'product_name:' . $request->product_name . '*',
                'default_operator' => 'AND'
            ]

Upvotes: 0

Related Questions