Alexander Shavelev
Alexander Shavelev

Reputation: 324

ElasticSearch dont return result

im new with elastic and can't solve this problem

i have 2 requests:

1) curl -XGET 'host/process_test_1/1/_search?title:*New*'

it returns me

    {
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 116,
    "max_score": 1.0,
    "hits": [
      {
        "_index": "process_test_1",
        "_type": "1",
        "_id": "7118_folder_1",
        "_score": 1.0,
        "_source": {
          "obj_type": "folder",
          "obj_id": 7118,
          "title": "sadasd"
        }
      },
      {
        "_index": "process_test_1",
        "_type": "1",
        "_id": "6780_folder_1",
        "_score": 1.0,
        "_source": {
          "obj_type": "folder",
          "obj_id": 6780,
          "title": "New Object"
        }
      }
    }
  ]
}
}

why it returns me an object with title "sadasd"?

and second request

`curl -XGET 'host/process_test_1/1/_search' -d '{"query":{"match":{"text":{"query":"*New*","operator":"and"}}}}`'

it returns

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

    ]
  }
}

why it return me nothins if i really have one element which match (actually i have more than 50 elements with such name and different ids)

Upvotes: 0

Views: 40

Answers (1)

Val
Val

Reputation: 217554

First, your first query is missing the parameter name q=

curl -XGET 'host/process_test_1/1/_search?q=title:*New*'
                                          ^
                                          |
                                   this is missing

Second, the match query doesn't interpret the * character as a wildcard, so if you want an equivalent query using the DSL for the first query above, you need to be using the query_string query instead:

curl -XGET 'host/process_test_1/1/_search' -d '{
  "query": {
    "query_string": {
      "query": "*New*",
      "default_field": "text"
    }
  }
}'

Upvotes: 2

Related Questions