我將任意嵌套物件存盤為扁平欄位“_meta”,其中包含與產品相關的各種資訊。這是該欄位的映射:
"mappings": {
"dynamic": "strict",
"properties": {
"_meta": {
"type": "flattened"
},
...
因此,在嘗試搜索時:
{
"query": {
"exists": {
"field": "_meta.user"
}
}
}
我期望檢索填充了該欄位的所有檔案。我得到零命中,但如果我搜索特定檔案,我可以看到至少一個檔案填充了該欄位:
"user": {
"origin_title": "some title",
"origin_title_en": "some other title",
"address": "some address",
"performed_orders_count": 0,
"phone": "some phone",
"name": "some name",
"tariff": null,
"proposal_image_background_color": null
},
那么通過展平的資料欄位進行搜索究竟是如何作業的呢?為什么我沒有得到任何結果?
uj5u.com熱心網友回復:
特長;
這是因為flattened欄位的作業方式。
在你的情況下:
{
"_meta":{
"user": {
"name": "some name"
}
}
}
Elasticsearch 可用的表示有:
{
"_meta": ["some name"],
"_meta.user.name": "some name"
}
重現
對于設定:
PUT /74025685/
{
"mappings": {
"dynamic": "strict",
"properties": {
"_meta":{
"type": "flattened"
}
}
}
}
POST /_bulk
{"index":{"_index":"74025685"}}
{"_meta":{"user": "some user"}}
{"index":{"_index":"74025685"}}
{"_meta":{"user": null, "age": 10}}
{"index":{"_index":"74025685"}}
{"_meta":{"user": ""}}
{"index":{"_index":"74025685"}}
{"_meta":{"user": {"username": "some user"}}}
此查詢將找到 2 條記錄:
GET 74025685/_search
{
"query": {
"term": {
"_meta": {
"value": "some user"
}
}
}
}
這個,只會匹配第一個檔案:
GET 74025685/_search
{
"query": {
"term": {
"_meta.user": {
"value": "some user"
}
}
}
}
因此對于存在查詢:
這個只會回傳最后一個檔案。
GET 74025685/_search
{
"query": {
"exists": {
"field": "_meta.user.username"
}
}
}
而這個作業系統將回傳第一個和第三個:
GET 74025685/_search
{
"query": {
"exists": {
"field": "_meta.user"
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/514339.html
標籤:弹性搜索
上一篇:Kibana-更新默認搜索查詢
