Не совсем уверен, как выглядит ваше отображение индекса.У меня есть два примера:
1 Имя содержится в одном поле:
PUT t2/doc/1
{
"name":"Joe Gray"
}
PUT t2/doc/2
{
"name":"J Gray"
}
POST t2/_search
{
"query": {
"match": {
"name": "j gray"
}
}
}
##Result
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.51623213,
"hits": [
{
"_index": "t2",
"_type": "doc",
"_id": "2",
"_score": 0.51623213,
"_source": {
"name": "J Gray"
}
},
{
"_index": "t2",
"_type": "doc",
"_id": "1",
"_score": 0.25811607,
"_source": {
"name": "Joe Gray"
}
}
]
}
}
2 Если у вас есть имя в виде двух отдельных полей (из того, что я заметил в комментариях) - вы можете использовать запрос bool
с предложением should
:
PUT t3/doc/1
{
"firstname":"Joe",
"lastname":"Gray"
}
PUT t3/doc/2
{
"firstname":"J",
"lastname":"Gray"
}
POST t3/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"firstname": "J"
}
},
{
"match": {
"lastname": "Gray"
}
}
]
}
}
}
## Result
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.5753642,
"hits": [
{
"_index": "t3",
"_type": "doc",
"_id": "2",
"_score": 0.5753642,
"_source": {
"firstname": "J",
"lastname": "Gray"
}
},
{
"_index": "t3",
"_type": "doc",
"_id": "1",
"_score": 0.2876821,
"_source": {
"firstname": "Joe",
"lastname": "Gray"
}
}
]
}
}