Elasticsearch 嵌套查询过滤器

Elasticsearch Nest Query Filter

我想通过过滤器获取记录。

Sql 查询:

SELECT * FROM testdb  Where contactId = "e84aca88-7b82-43d9-8788-4cc25af0c43a"

Json 查询:

{
    "from": 0,
    "size": 200,
    "query": {
        "filtered": {
            "filter": {
                "bool": {
                    "must": {
                        "query": {
                            "match": {
                                "contactId": {
                                    "query": "e84aca88-7b82-43d9-8788-4cc25af0c43a",
                                    "type": "phrase"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

如何使用此查询进行嵌套搜索?

您的查询有误。它应该像这样工作:

{
    "from": 0,
    "size": 200,
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "contactId": "e84aca88-7b82-43d9-8788-4cc25af0c43a"
                    }
                }
            ]
        }
    }
}

在复制和粘贴之前,请查看此查询格式并阅读有关 bool 查询和使用 match:

的信息

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html

此外,检查 Elasticsearch 的 Inquisitor 插件,这将帮助您构建查询和测试查询格式:

https://github.com/polyfractal/elasticsearch-inquisitor

我想像这个查询一样使用 C# Nest

client.Search<Contact>(s => s.Query(q => q.Term(p => p.ContactId, "e84aca88-7b82-43d9-8788-4cc25af0c43a")));

所以我必须将 json 查询转为 Nest 查询