Hi,
Am using nested data type for to create index
POST _my_index1
{
"mappings": {
"_doc": {
"properties": {
"user": {
"type": "nested"
}
}
}
}
}
Inserted data
curl -XPOST -H "Content-Type: application/json" "http://localhost:9200/my_index1/_doc/1" -d '{
"group" : "fans",
"user" : [
{
"first" : "John",
"last" : "Smith"
}
]
}'
curl -XPOST -H "Content-Type: application/json" "http://localhost:9200/my_index1/_doc/1" -d '{
"group" : "fans",
"user" : [
{
"first" : "John1",
"last" : "Smith1"
}
]
}'
Need to fech date which matches first name like '%john%'. Tried with Elasticsearch
GET
{
"_source": ["user"],
"query": {
"bool": {
"must": [
{
"nested": {
"path": "user",
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "user.first",
"query": "John*"
}
}
]
}
}
}
}
],
"filter": {
"terms": {
"_id": [ "2"]
}
}
}
}
}
OUTPUT
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "my_index1",
"_type": "_doc",
"_id": "2",
"_score": 1,
"_source": {
"user": [
{
"last": "Smith",
"first": "John"
},
{
"last": "White",
"first": "Alice"
}
]
}
}
]
}
}
Please help me how to make like query without using wildcard this it may cause super slow.
Thanks,
Veera