代码之家  ›  专栏  ›  技术社区  ›  loretoparisi

组合查询字符串,并且必须在弹性搜索node.js客户端中

  •  0
  • loretoparisi  · 技术社区  · 6 年前

    我在做一个 search tags 数组字段,它必须与某些查询匹配,如 entity.color:green ,所以我想

    {
        body: {
            "query": {
                "bool": {
                    "must": [{
                            "exists": {
                                "field": "tags"
                            }
                        },
                        {
                            "query_string": {
                                "query": "entity.color:green"
                            }
                        },
                        {
                            "match": {
                                "entity.color": "green"
                            }
                        }
                    ],
                    "must_not": [{
                            "term": {
                                "tags": ""
                            }
                        },
                        {
                            "term": {
                                "tags": "[]"
                            }
                        }
                    ]
                }
            }
        },
        size: 10,
        index: myIndex
    }
    

    但我没有得到任何结果。没有 query_string 返回正确的筛选项,但添加时不返回。 我正在运行最新版本的 elastic search node.js client 15.2.0条

    我也试过嵌套 bool/must

    {
        "bool": {
            "must": [{
                    "exists": {
                        "field": "tags"
                    }
                },
                {
                    "bool": {
                        "must": [{
                                "query_string": {
                                    "query": "entity.color:green"
                                }
                            },
                            {
                                "match": {
                                    "entity.color": "green"
                                }
                            }
                        ]
                    }
                }
            ],
            "must_not": [{
                    "term": {
                        "tags": ""
                    }
                },
                {
                    "term": {
                        "tags": "[]"
                    }
                }
            ]
        }
    }
    
    0 回复  |  直到 6 年前