Elasticsearch Nest查询过滤器

时间:2015-06-03 13:59:20

标签: sql sql-server elasticsearch nest

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

Sql Query:

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"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

如何通过嵌套搜索此查询?

2 个答案:

答案 0 :(得分:0)

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

{
    "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

答案 1 :(得分:0)

我想像C#这样的查询

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

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