1

我有一个如下查询,

任何想法,为什么我在搜索时只得到完全匹配的结果。例如 ;

当我搜索“Aegli”时,我得到了结果,但是当我搜索“Aegl”时,没有返回结果

query = {
  "query": {
    "query_string": {
      "query": "%s"%q
    }
  },
  "filter": {
    "term": {
      "has_product": 1
    }
  },
  "facets": {
    "destination": {
      "terms": {
        "field": "destination.en"
      },
      "facet_filter": {
        "term": {
          "has_product": 1
        }
      }
    },
    "hotel_class": {
      "terms": {
        "field": "hotel_class"
      },
      "facet_filter": {
        "term": {
          "has_product": 1
        }
      }
    },
    "hotel_type": {
      "terms": {
        "field": "hotel_type"
      },
      "facet_filter": {
        "term": {
          "has_product": 1
        }
      }
    }
  }
}
4

2 回答 2

1

I do not see your real query but you might be missing * at end of your search word and your query string should be like;

{"query_string": {"query": "%s*"}

For example;

{"query_string": {"query": "Aegl*"}
于 2013-05-29T08:34:25.637 回答
0

具有如下映射

{
    "mappings": {
        "hotel": {
            'properties': {"name": {
                "type": "string",
                "search_analyzer": "str_search_analyzer",
                "index_analyzer": "str_index_analyzer"
            }
            }},

    },

    "settings": {
        "analysis": {
            "analyzer": {
                "str_search_analyzer": {
                    "tokenizer": "keyword",
                    "filter": ["lowercase"]
                },

                "str_index_analyzer": {
                    "tokenizer": "keyword",
                    "filter": ["lowercase", "substring"]
                }
            },

            "filter": {
                "substring": {
                    "type": "nGram",
                    "min_gram": 1,
                    "max_gram": 20
                }
            }
        }
    }
}

解决了我的问题

于 2013-05-29T20:41:40.240 回答