简体   繁体   English

如何在ElasticSearch中向常用术语查询添加多个字段?

[英]How to add multiple fields to a common terms query in ElasticSearch?

I have a common term query like so. 我有一个像这样的共同术语查询。

{
    "query" : {
        "common" : {
            "DocumentData.OCR_Text" : {
                "query" : "block 310 luis",
                "cutoff_frequency" : 0.001
            }
        }
    }
}

I want to search on 2 or more fields but this gives me an error. 我想搜索2个或更多字段,但这给了我一个错误。

{
    "query" : {
        "common" : {
            "Grantors" : {
                    "query" : "block 310 luis",
                    "cutoff_frequency" : 0.001
                },
            "DocumentData.OCR_Text" : {
                "query" : "block 310 luis",
                "cutoff_frequency" : 0.001
            }
        }
    }
}

nested: ElasticsearchParseException[Expected field name but got START_OBJECT "DocumentData.OCR_Text"]; 嵌套:ElasticsearchParseException [预期字段名称但得到START_OBJECT“DocumentData.OCR_Text”];

How would you do this? 你会怎么做?

You should wrap it in a Bool Query 您应该将其包装在Bool查询中

{
    "query": {
        "bool": {
            "should": [
                {
                    "common": {
                        "Grantors": {
                            "query": "block 310 luis",
                            "cutoff_frequency": 0.001
                        }
                    }
                },
                {
                    "common": {
                        "DocumentData.OCR_Text": {
                            "query": "block 310 luis",
                            "cutoff_frequency": 0.001
                        }
                    }
                }
            ]
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM