- cross_fields字段:在查询阶段解决信号冲突问题
- 问题: The cross_fields type is particularly useful with structured documents where multiple fields should match. For instance, when querying the first_name and last_name fields for “Will Smith”, the best match is likely to have “Will” in one field and “Smith” in the other.
- 解决:The cross_field type tries to solve these problems at query time by taking a term-centric approach. It first analyzes the query string into individual terms, then looks for each term in any of the fields, as though they were one big field.
GET _search
{
"size": 20,
"_source": "title",
"explain": true,
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "star trek patrick stewart",
"fields": [
"overview","title","directors.name","cast.name"],
"type": "cross_fields"
}
},
{"multi_match": {
"query": "star trek patrick stewart",
"fields": [
"directors.name.bigramed","cast.name.bigramed"],
"type": "cross_fields",
"boost":100
}}
]
}
}
}
GET _search
{
"size": 10,
"_source": "title",
"explain": true,
"query":{
"bool":{
"should": [
{
"match_phrase": {
"title_exact_match":{
"query":"SENTINEL_BEGIN star trek SENTINEL_END",
"boost":1000
}
}},
{
"multi_match": {
"query": "star trek",
"fields": [
"overview","title","directors.name","cast.name"],
"type": "cross_fields"
}
}
]
}
}
}
GET _search
{
"size": 10,
"_source": "title",
"explain": true,
"query": {
"function_score": {
"query": {
"multi_match": {
"query": "william shatner patrick stewart",
"fields": [
"overview",
"title",
"directors.name",
"cast.name"
],
"type": "cross_fields"
}
},
"functions": [
{
"weight": 2.5,
"filter": {
"match_phrase": {
"title": "star trek"
}
}
}
]
}
}
}