簡體   English   中英

如何在字段上進行查詢,我尚未定義映射

[英]how to make a query on a field I have not defined a mapping for

我有一個要添加到品牌中的current_country字段,並且在我的Elasticsearch映射中尚未定義。

我想對此進行過濾查詢,因為未定義它,我想它沒有被分析並且術語查詢應該起作用。

這是我在做的查詢

{
    "index": "products",
    "type": "brand",
    "body": {
        "from": 0,
        "size": 100,
        "sort": [
            {
                "n_name": "asc"
            }
        ],
        "query": {
            "filtered": {
                "query": {
                    "function_score": {
                        "filter": {
                            "bool": {
                                "must": [
                                    {
                                        "term": {
                                            "current_country": "DK"
                                        }
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        }
    }
}

該索引不返回任何文檔。

我運行以下查詢以檢查當前國家/地區是否存在

{
    "index": "products",
    "type": "brand",
    "body": {
        "from": 0,
        "size": 100,
        "sort": [
            {
                "n_name": "asc"
            }
        ],
        "query": {
            "filtered": {
                "query": {
                    "function_score": {
                        "filter": {
                            "bool": {
                                "must": [
                                    {
                                        "exists": {
                                            "field": "current_country"
                                        }
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        }
    }
}

總共返回693個文檔。

這是索引中的示例文檔,當我運行上述查詢時返回。

{
    "_index": "products",
    "_type": "brand",
    "_id": "195da951241478LuxoLivingbrand",
    "_score": null,
    "_source": {
        "categories": [
            "Bordlamper og designer bordlamper der giver liv og lys"
        ],
        "image": "http://www.fotoagent.dk/single_picture/11385/138/mega/and_tradition_flowerpot_bordlampe_lilla.jpg",
        "top_price": 1695,
        "low_price": 1695,
        "n_name": "&Tradition",
        "name": "&Tradition",
        "current_country": "DK",
        "current_currency": "DKK"
    }
}

如何查詢current_country(最好是經過過濾的查詢)。

如果您沒有為字段定義任何映射,elasticsearch會嘗試將字段檢測為字符串/日期/數字。 如果它將字段檢測為字符串,則它將使用默認分析器(標准分析器)來分析您的輸入。 由於標准分析器使用小寫標記過濾器,因此您輸入的字符串被索引為“ dk”。 由於術語過濾器不會分析輸入,因此“ DK”將與“ dk”不匹配。

可以通過多種方式解決。

  1. (hack)您可以小寫輸入過濾條件。 這不適用於短語。

  2. (更好)為您的輸入定義映射。 您可以動態更改映射/ 輕松添加新映射

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM