我的樣本指數和文件結構如下所示:彈性搜索添加砝碼或提高查詢和多期限條款
http://localhost:9200/testindex/
{
"settings": {
"analysis": {
"analyzer": {
"autocomplete": {
"tokenizer": "whitespace",
"filter": [
"lowercase",
"autocomplete"
]
},
"autocomplete_search": {
"tokenizer": "whitespace",
"filter": [
"lowercase"
]
}
},
"filter": {
"autocomplete": {
"type": "nGram",
"min_gram": 2,
"max_gram": 40
}
}
}
},
"mappings": {
"table1": {
"properties": {
"title": {
"type": "string",
"index": "not_analyzed"
},
"type": {
"type": "string",
"index": "not_analyzed"
},
"type1": {
"type": "string",
"index": "not_analyzed"
},
"id": {
"type": "string",
"analyzer": "autocomplete",
"search_analyzer": "autocomplete_search"
}
}
}
}
}
http://localhost:9200/testindex/table1/1
{
"title": "mumbai",
"type": "efg",
"type1": "efg1",
"id": "Caryle management"
}
http://localhost:9200/testindex/table1/2
{
"title": "canada",
"type": "abc",
"type1": "abc1",
"id": "labson series 2014"
}
http://localhost:9200/testindex/table1/3/
{
"title": "ny",
"type": "abc",
"type1": "abc1",
"id": "labson series 2012"
}
http://localhost:9200/testindex/table1/4/
{
"title": "pune",
"type": "abc",
"type1": "abc1",
"id": "hybrid management"
}
Query used to get all documents where type = "abc" and "efg" and have id equal to labson and management .
{
"query": {
"bool": {
"filter": {
"query": {
"terms": {
"type": [
"abc",
"efg"
]
}
}
},
"minimum_should_match": 1,
"should": [
{
"query": {
"bool": {
"must": [
{
"term": {
"_type": "table1"
}
},
{
"bool": {
"should": [
{
"match": {
"id": {
"query": "labson ",
"operator": "and"
}
}
},
{
"match": {
"id": {
"query": "management",
"operator": "and"
}
}
}
]
}
}
]
}
}
}
]
}
}
}
"hits": [
{
"_index": "testindex",
"_type": "table1",
"_id": "2",
"_score": 1,
"_source": {
"title": "canada",
"type": "abc",
"type1": "abc1",
"id": "labson series 2014"
}
}
,
{
"_index": "testindex",
"_type": "table1",
"_id": "4",
"_score": 1,
"_source": {
"title": "pune",
"type": "abc",
"type1": "abc1",
"id": "hybrid management"
}
}
,
{
"_index": "testindex",
"_type": "table1",
"_id": "1",
"_score": 1,
"_source": {
"title": "mumbai",
"type": "efg",
"type1": "efg1",
"id": "Caryle management"
}
}
,
{
"_index": "testindex",
"_type": "table1",
"_id": "3",
"_score": 1,
"_source": {
"title": "ny",
"type": "abc",
"type1": "abc1",
"id": "labson series 2012"
}
}
]
所以我需要幫助對該輸出的問題。
- 爲什麼labson系列2012在結果 最後文件呢?雖然我的搜索條件要首先考慮labson和 然後管理我。怎麼能在管理提升中添加或重量labson關鍵字 。所以輸出應該給我所有文件, 匹配labson然後管理根據輸入的順序在 匹配條款。
- 我該如何添加一個過濾器在頂部應該閱讀有給我所有 有輸入(「abc」,「efg」)和type1在 (「abc」)的文檔。現在我只是在「(abc」,「efg」)中搜索類型,如何修改查詢以包含type1字段的IN子句。
請對上述2查詢解決方案提供一些僞代碼,因爲我是新來的ES,這將幫助我非常
在此先感謝
因此,如果我必須增加從上到下的提升參數,我應該把第一個匹配作爲最大值,然後以降序排列,直到最後一個匹配的最小值爲1。 – baiduXiu
在相同的查詢中,如果我必須指定不在(「abc」,「efg」)中的類型而不是在(「abc」,「efg」)中,我們如何在ES中執行此操作 – baiduXiu
另外, 4,我嘗試了2和3,但沒有奏效,但它與4一起工作。所以我們如何決定提升因子 – baiduXiu