没有得到所有结果 [英] Not getting all the results

查看:58
本文介绍了没有得到所有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我与上一个问题相关的问题,我之前问过搜索在之后停止第一场比赛

This is my question related to my previous question that I asked search stops after the first match

在这里,我正在为您提供映射.

Here I am giving you the mapping.

{
    "copy_order_snapshot": {
        "properties": {
            "line_item_info": {
                "dynamic": "true",
                "properties": {
                    "m_product_details": {
                        "dynamic": "true",
                        "properties": {
                            "accessories_colour": {
                                "type": "string"
                            },
                            "status": {
                                "type": "string"
                            }
                        }
                    },
                    "other_details": {
                        "dynamic": "true",
                        "properties": {
                            "accessories_material_type": {
                                "type": "string"
                            }
                            "status": {
                                "type": "string"
                            }
                        }
                    },
                    "product_details": {
                        "dynamic": "true",
                        "properties": {
                            "accessories_colour": {
                                "type": "string"
                            },
                            "status": {
                                "type": "string"
                            }
                        }
                    }
                }
            },
            "order_data": {
                "dynamic": "true",
                "properties": {
                    "state": {
                        "type": "string"
                    },
                    "status": {
                        "type": "string"
                    }                    
                }
            }
        }
    }
}

在我之前的问题中,我谈论的是 attribute_set_id ,这里的情况与 status 相同. order_details->状态为已启用" ,而其他状态为"1"和已取消" .当我搜索

In my previous question I was talking about attribute_set_id , here the same case is with status. The order_details->status is "enabled" while the other status are as "1" and "canceled". When I search for

{
    "query":{
        "term":{
            "status":"enabled"
         }
    }
}

我得到结果

但是如果我搜索

{
    "query":{
        "term":{
            "status":"1"
        }
    }
}

{
    "query":{
        "term":{
            "status":"canceled"
        }
    }
}

我没有结果.

请帮助.

推荐答案

由于字段名称状态"不明确而发生.在查询处理期间,elasticsearch将字段名称"status"解析为与其匹配的第一个完全限定的字段名称.当我在计算机上运行它时,它解析为line_item_info.other_details.status.

It happens because of ambiguous field name "status". During query processing, elasticsearch resolves the field name "status" into the first fully qualified field name that it matches. When I ran it on my machine, it got resolved into line_item_info.other_details.status.

$ curl "localhost:9200/test-orders/_validate/query?q=status:blah&explain=true&pretty=true"
{
  "valid" : true,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "explanations" : [ {
    "index" : "test-orders",
    "valid" : true,
    "explanation" : "line_item_info.other_details.status:blah"
  } ]
}

如果您希望查询匹配所有状态字段,则可能需要使用完全限定的名称(例如 line_item_info.other_details.status line_item_info.m_product_details.status 等等),并使用 Dis Max 布尔查询.

If you want your query to match all status fields, you might need to use fully qualified names (such as line_item_info.other_details.status, line_item_info.m_product_details.status, etc.) and combine them using Dis Max or Bool Queries.

例如:

$ curl -XGET http://localhost:9200/test-orders/copy_order_snapshot/_search -d '{
    "query":{
        "bool" : {
            "should" : [
                {
                    "term" : { "line_item_info.m_product_details.status" : "1" }
                },
                {
                    "term" : { "line_item_info.other_details.status" : "enabled" }
                }
            ]
        }
    }
}'

这篇关于没有得到所有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆